Find nearest grid cell between two 2D matrixes of different resolution
2 views (last 30 days)
Show older comments
Melissa
on 15 May 2015
Commented: Walter Roberson
on 15 May 2015
Hello,
I have two matrices I would like to compare.
A is 192(lon) x 288(lat) B is 360(lat) x 720(lon)
How can I regrid B so that its resolution is the same as A?
I would like to know how to do this both by finding the nearest B lat&lon&values for A, and also by decimating B to the coarser resolution of A
Thank you,
Melissa
0 Comments
Accepted Answer
Walter Roberson
on 15 May 2015
Assuming that they are regular grids with known latitude and longitude vectors, Along, Alat, Blong, Blat, then the approximation that neglects curvature of the Earth would be
[X, Y] = meshgrid(Blat, Blong);
[Xq, Yq] = meshgrid(Alat, Along);
Bapprox = interp2(X, Y, B, Xq, Yq);
The interp2() would need the longitude vectors phase-unwrapped if they cross 180 to -180:
degrad = pi./180;
unwrappedBlong = unwrap(Blong .* degrad) ./ degrad;
If you do need to take the curvature of the Earth into account, then possibly mapprofile might turn out to be usable for you -- I am too tired at the moment to figure out what a refmatrix is.
If mapprofile is not suitable then perhaps someone has already built a routine. If not then intrplon might help.
2 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!