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

1 vue (au cours des 30 derniers jours)
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;
clc;
h=openfig('Fig2m005.fig'); %%%% Load graphic
h=findobj(gca,'Type','line'); %%%% Make program read graphic
x=get(h,'Xdata'); %%%% Values
y=get(h,'Ydata');
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');
B=[];
B(:,1)=x_i;
B(:,2)=y_i;
dlmwrite('m005_interp1.txt',B,',');
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
xlabel('ds/gT^2')
ylabel('Hb/ds')
axis ([0 0.02 0 2])

Réponse acceptée

Hjodie
Hjodie le 9 Nov 2019
Modifié(e) : Hjodie le 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
y_read=y_i(x_place)

Plus de réponses (0)

Catégories

En savoir plus sur Discrete Data Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by