Interpolating from one grid to another

5 次查看(过去 30 天)
Hello experts
Please, could someone help me with an interpolation?
I have two different 2D scattered grids (X = longitude, Y = depth), and a variable temperature, from two different datasets. On the first one x and y are 41x37, and on the second 24x10. Also Temp1 (41x37) and Temp2 (24x10).
I need to compute the difference (Temp1 - Temp2), but for that, I need Temp2 to be on the same format (and coordenates) as Temp1, that is, 41x37. Then, I guess I have to interpolate X2, Y2, Temp2, to the coordinates of X1, Y1.
I tried scatteredInterpolant function, but I it doesn't work, moreover, it does not allow me to inform the reference coordinates, that is, X1,Y1.
Both scatteredInterpolant and TriScatteredInterp has the structure F = function(x,y,v), but I need something like NewTemp2 = function(X1,Y1,X2,Y2,Temp2).
Please, could someone help me with this?
The data is attached, thank you very much in advance!

采纳的回答

Star Strider
Star Strider 2024-4-5
编辑:Star Strider 2024-4-5
It appears that ‘Temp1’ seems to not have made it to the save function argument llist.
This interpolates ‘Temp2’ to the (X1,Y1) grids using scatteredInterpolant
load('data.mat')
whos
Name Size Bytes Class Attributes Temp2 24x10 1920 double X1 41x37 12136 double X2 24x10 1920 double Y1 41x37 12136 double Y2 24x10 1920 double ans 1x32 64 char cmdout 1x33 66 char gdsCacheDir 1x14 28 char gdsCacheFlag 1x1 8 double i 0x0 0 double managers 1x0 0 cell managersMap 0x1 8 containers.Map
figure
surfc(X2, Y2, Temp2)
grid on
xlabel('X2')
ylabel('Y2')
zlabel('Temp2')
X2Y2 = [X2(:), Y2(:)];
X2Y2(isinf(X2Y2)) = NaN;
X2Y2 = fillmissing(X2Y2, 'linear');
X2v = X2Y2(:,1);
Y2v = X2Y2(:,2);
FTemp2 = scatteredInterpolant(X2v(:), Y2v(:), Temp2(:));
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Temp2i = FTemp2(X1, Y1);
figure
surfc(X1, Y1, Temp2i)
grid on
xlabel('X1')
ylabel('Y1')
zlabel('Temp2 — Interpolated To (‘X1,Y1’)')
Do the same sort of approach to interpolate ‘Temp1’ to the ‘Temp2’ grids, if necessary.
EDIT — Corrected typographical errors.
.
  13 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by