MATLAB Answers

how can I solve this problem?

조회 수: 4(최근 30일)
Sharon García Herbert
댓글: Jacob Wood 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 :)

  댓글 수: 0

로그인 to comment.

답변(2개)

Jacob Wood
Jacob Wood 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

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 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);

로그인 to comment.


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

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그


Translated by