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일

1 개 추천

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
Sharon García Herbert 2020년 2월 26일
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?
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일

0 개 추천

idx = x ==1 ;
y(idx)
z(idx)

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

태그

질문:

2020년 2월 26일

댓글:

2020년 2월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by