MATLAB Answers

How to get Y values corresponding to X from matrix B nx2 or from X and Y matrices

7 views (last 30 days)
Hjodie on 9 Nov 2019
Edited: Hjodie on 9 Nov 2019
We have the data of matrix B (201x2) which consist of x_i (1x201) and y_i (1x201) matrices.
We want program to prompt y_i value corresponding to x_i value that we will write.
I'm open for other solutions too.
(Don't mind the part before %%%% INTERP1 %%%% )
clear all;
close all;
h=openfig('Fig2m005.fig'); %%%% Load graphic
h=findobj(gca,'Type','line'); %%%% Make program read graphic
x=get(h,'Xdata'); %%%% Values
A=[]; %%%% Create empty matrix so you can put x and y
A(:,1)=x; %%%% Put x values to 1st column
A(:,2)=y; %%%% Put y values to 2st column
dlmwrite('m005.txt',A,','); %%%% Write A matrix as a txt text file, value that we selected by hand
%%%% INTERP1 %%%%
x_i = 0:0.0001:0.02;
y_i = interp1(x, y, x_i, 'linear');
figure(2) %%%% Creates new window for new interpolated graph ( as you can see there is no difference )
plot(x_i, y_i,'g') %%%% line names in data file
title('Dimensionless design breaker height versus relative depth at structure') %% naming
axis ([0 0.02 0 2])

Accepted Answer

Hjodie on 9 Nov 2019
Edited: Hjodie on 9 Nov 2019
Problem is caused because of the decimal use and format ( I guess ).
x_input=input('Put X value to read y_i= ')
x_place=find(abs(x_i-x_input)<10^-6) %right to 10^-6

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by