how can I solve this problem?

1 Ansicht (letzte 30 Tage)
Sharon García Herbert
Sharon García Herbert am 26 Feb. 2020
Kommentiert: Jacob Wood am 26 Feb. 2020
Hi,
I have the following set of data:
x=[0;0;0;0;0;1;1;1;1;1;2;2;2;2;2];
y=[0;1;2;3;4;0;1;2;3;4;0;1;2;3;4];
z=[10;11;12;13;14;15;16;17;18;19;20;21;22;23;24];
Now I want to know what the value of y and z if I x=1.
To solve this problem, I have tried to use the function interp2. But I get an error.
Can somebody help me with this?
Thanks :)

Antworten (2)

Jacob Wood
Jacob Wood am 26 Feb. 2020
Hi Sharon,
This is a perfect application for Matlab's logical indexing.
x_is_one = x == 1; %find locations where x=1
y_select = y(x_is_one); %pick y where x=1
z_select = z(x_is_one); %pick z where x=1
  2 Kommentare
Sharon García Herbert
Sharon García Herbert am 26 Feb. 2020
x=[0.01,3,6,9,12,15,18];
y=[0.6113,0.7577,0.9349,1.1477,1.4022,1.7051,2.0640];
z=[206.136,168.132,137.734,113.386,93.784,77.926,65.038];
scatter3(x,y,z,'filled')
hold on
xlabel('temp')
ylabel('presion')
zlabel('volumen')
hold off
grid minor
x_is_one= x==1; %find locations where x=1
y_select=y(x_is_one); %pick y where x=1
z_select=z(x_is_one); %pick z where x=1
I did that, but I'm not sure if it is right, could you please continue to help me out?
Jacob Wood
Jacob Wood am 26 Feb. 2020
Hi Sharon,
It doesn't look like X=1 at any point in this example. Would you instead like to interpolate the vectors, and see what y and z would be when x theoretically crosses 1?
x=[0.01,3,6,9,12,15,18];
y=[0.6113,0.7577,0.9349,1.1477,1.4022,1.7051,2.0640];
z=[206.136,168.132,137.734,113.386,93.784,77.926,65.038];
y_select = interp1(x,y,1);
z_select = interp1(x,z,1);

Melden Sie sich an, um zu kommentieren.


KSSV
KSSV am 26 Feb. 2020
idx = x ==1 ;
y(idx)
z(idx)

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by