Interpolate x,y coordinates and timesteps

Heallo,
I have an array M with x, y, coordinates points in the 1st and 2nd column [x= M(2:end,1); y= M(2:end,2)]. The following columns are the values (for example temperatures) for different timesteps [timesteps = M(1,3:end].
How can I interpolate the x,y coordinates and the timesteps?
clc
clear
M(5,7)=0;
M(1,2:7)=0:10:50;
M(2:5,1)=1:4;
M(2:5,2)=1:0.5:2.5;
M(2,3:7)=100:3:112;
M(3,3:7)=110:3:122;
M(4,3:7)=120:3:132;
M(5,3:7)=120:3:132;

댓글 수: 5

Mathieu NOE
Mathieu NOE 2024년 3월 4일
seems to me (if I understand correctly) that x and y are not independant variables.
we can do a 2D interpolation beetween x and time (or y and time , as x and y are linked) , but we cannot make any 3D interpolation as if x,y and time are independant data.
Yes, you are right. x and y are linked, because for example M(2,1) is the x-value and M(2,2) is the corresponding y-value.x and y are coordinates of a specific point.
So, like this...or is there a better solution?
clc
clear
MM(5,7)=0;
MM(1,2:7)=0:10:50;
MM(2:5,1)=1:4;
MM(2:5,2)=1:0.5:2.5;
MM(2,3:7)=100:3:112;
MM(3,3:7)=110:3:122;
MM(4,3:7)=120:3:132;
MM(5,3:7)=120:3:132;
X= MM(2:5,1);
time= MM(1,3:7);
V = MM(2:5,3:7)';
[XX,TIME] = meshgrid(X,time);
x_query = [1.5];
time_query = [25];
query_values_M = interp2(XX,TIME,V,x_query,time_query)
Mathieu NOE
Mathieu NOE 2024년 3월 5일
exact !!
thank you for your help
Mathieu NOE
Mathieu NOE 2024년 3월 5일
my pleasure !!

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

답변 (1개)

Florian Bidaud
Florian Bidaud 2024년 3월 4일
In your example, you only have a 2D M array, but I guess what you want is a 3D interpolation, so with another dimension in M ?
M = [[103,113,123,123]',[106,116,126,126]',[109,119,129,126]',[112,122,132,132]'];
% Building an example of a 3 dimensional array
values(:,1,:) = M;
values(:,2,:) = M*1.05;
values(:,3,:) = M*1.1;
values(:,4,:) = M*1.15;
timesteps = (20:10:50)';
x = (1:4)';
y = (1:0.5:2.5)';
% query values
x_query = [1.1 3.2];
y_query = [1.3 2.2];
time_query = [21 45];
query_values = interp3(x,y,timesteps,values,x_query,y_query,time_query)
query_values = 1×2
109.8465 144.1890

댓글 수: 1

Sorry my question was not clear. x and y-values are not independant variables. But thanks for your help

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

카테고리

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

질문:

2024년 3월 4일

댓글:

2024년 3월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by