Interpolating from one grid to another

9 views (last 30 days)
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!

Accepted Answer

Star Strider
Star Strider on 5 Apr 2024
Edited: Star Strider on 5 Apr 2024
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 Comments
Luís Henrique Bordin
Luís Henrique Bordin on 23 Apr 2024
Okay. Thank you very much, have a good day!
Star Strider
Star Strider on 23 Apr 2024
As always, my pleasure!
You, too!

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!