Hi all;
I have a table temperature (35040 X 6),
Space mesh (1 X 104),
And Z_sensor (1 X 6)
I want to interpolate them to find the initial temperature using a for loop. Can someone help me with that?
Thank you!
for i =1: length(z_mesh)
T(i,1) = interp1( z_mesh, temp(i,:), z_sensor,'linear');
end

댓글 수: 6

Torsten
Torsten 2023년 11월 18일
Your question is not clear.
You usually have x and y data of the same length and you try to interpolate y (yq) at a new given x-position xq. What are x,y and xq in your case ?
Sanley Guerrier
Sanley Guerrier 2023년 11월 18일
In my case x is z_sensor , y is Temp, xq is z_mesh.
Torsten
Torsten 2023년 11월 18일
So you want to interpolate 6 temperatures at 6 positions to 104 other positions ? And the 35040 rows are the temperatures at the 6 positions at different times ?
Sanley Guerrier
Sanley Guerrier 2023년 11월 18일
Yes, correct.
Torsten
Torsten 2023년 11월 18일
편집: Torsten 2023년 11월 18일
Is it correct then that you are given a single value for time (tq) and a single value for z_mesh (xq) and you want to interpolate Tq from a given time vector t, a sensor vector x (z_sensor) and a temperature matrix T ?
Then study how to use "interp2" instead of "interp1".
E.g.
tstart = 0;
tend = 10;
dt = 0.1;
zstart = 0;
zend = 1;
dz = 0.1;
z = zstart:dz:zend;
t = (tstart:dt:tend)';
T = z.^2+t.^2;
tq = 9.25;
zq = 0.135;
Tq = interp2(z,t,T,zq,tq)
Tq = 85.5855
Sanley Guerrier
Sanley Guerrier 2023년 11월 18일
Thank you!

댓글을 달려면 로그인하십시오.

 채택된 답변

Matt J
Matt J 2023년 11월 18일
편집: Matt J 2023년 11월 18일

0 개 추천

You don't need a for-loop to interpolate successive temp(i,:). Just do,
T = interp1(z_sensor, temp', z_mesh ,'linear');

댓글 수: 3

Sanley Guerrier
Sanley Guerrier 2023년 11월 18일
I need it because it will be used later to construct a matrix.
Matt J
Matt J 2023년 11월 18일
편집: Matt J 2023년 11월 18일
Whatever you are doing later is unrelated to the task you describe in your post. The code I gave you is equivalent to what the loop you posted is trying to do.
Sanley Guerrier
Sanley Guerrier 2023년 11월 18일
yes, you are right I can use it without a for loop. thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2023년 11월 18일

댓글:

2023년 11월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by