how can I solve this problem?

1 次查看(过去 30 天)
Sharon García Herbert
评论: Jacob Wood 2020-2-26
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 :)

回答(2 个)

Jacob Wood
Jacob Wood 2020-2-26
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 个评论
Sharon García Herbert
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 2020-2-26
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);

请先登录,再进行评论。


KSSV
KSSV 2020-2-26
idx = x ==1 ;
y(idx)
z(idx)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by