Clear Filters
Clear Filters

Interpolation using for loop

5 views (last 30 days)
Sanley Guerrier
Sanley Guerrier on 18 Nov 2023
Commented: Sanley Guerrier on 18 Nov 2023
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 Comments
Torsten
Torsten on 18 Nov 2023
Edited: Torsten on 18 Nov 2023
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

Sign in to comment.

Accepted Answer

Matt J
Matt J on 18 Nov 2023
Edited: Matt J on 18 Nov 2023
You don't need a for-loop to interpolate successive temp(i,:). Just do,
T = interp1(z_sensor, temp', z_mesh ,'linear');
  3 Comments
Matt J
Matt J on 18 Nov 2023
Edited: Matt J on 18 Nov 2023
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 on 18 Nov 2023
yes, you are right I can use it without a for loop. thanks.

Sign in to comment.

More Answers (0)

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!