2d interpolation from a non-uniform grid
Ältere Kommentare anzeigen
I have looked at the griddata function but am not clear if it applies to data on an irregular mesh. In my case, I have a 2d spatial dataset available on an [X,Y] grid where X and Y, which are the cartesian coordinates, are themselves 2d arrays. That is, both X and Y have sizes (m,n) but
X(:,1) ~= X(:,2) ~= X(:,3) and so on.
Similarly for the array Y. Visually, you can picturize the grid as follows, where X marks the location of the input data set:
X X X X
X X X X
X X X X
Along each row, the spacing between two Xs is uniform. But the spacing changes from row to row, leading to X(:,1), X(:,2), etc. all being different.
It looks like griddata will not accept such an input grid. Am I correct?
Thanks for your help.
4 Kommentare
Akira Agata
am 25 Jun. 2020
In that case, the data will not be treated as meshgrid. I belive there are 2 possible solutions:
Solution 1 (I think is better)
Solution 2
Extract half of your data ( X(1:2:end, 1:2:end) and Y(1:2:end, 1:2:end) ) and apply interp2 function.
oceanmod
am 25 Jun. 2020
oceanmod
am 25 Jun. 2020
Akira Agata
am 26 Jun. 2020
Well, let me clarify my intention by the following small example.
I hope this will be somehow helpful for you to understand how these two functions works.
% Original Data (X and Y are non-uniform grid)
X = [...
1 3 5 7;...
2 4 6 8;...
1 3 5 7;...
2 4 6 8];
Y = [...
1 1 1 1;
2 2 2 2;
3 3 3 3;
4 4 4 4];
Z = X.^2 + Y.^2;
% Query points
[xGrid, yGrid] = meshgrid(1:0.2:8,1:0.2:4);
% [Solution 1]
F = scatteredInterpolant(X(:),Y(:),Z(:));
zGrid = F(xGrid,yGrid);
% [Solution 2]
X2 = X(1:2:end,:);
Y2 = Y(1:2:end,:);
Z2 = Z(1:2:end,:);
zGrid2 = interp2(X2,Y2,Z2,xGrid,yGrid);
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Interpolation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!