MATLAB: Interpolation problem between two 2D global datasets

2dglobalinterp2interpolatelatitudelongitudemeshgridmonotonic

Hello,
I have two matrices I would like to compare.
First Matrix:
Serna (360×720)
lat (360×1)
lon (720×1)
Second Matrix:
first_model (288×192)
lat_model (192×1)
lon_model (288×1)
I would like to interpolate first_model to the dimensions of Serna. However, when I use this code:
[X, Y] = meshgrid(lat_model, lon_model); %first_model coordinates
[Xq, Yq] = meshgrid(lat, lon); %Serna coordinates
Serna_approx = interp2(X, Y, first_model', Xq, Yq);
I get the error that it is not monotonically increasing. However, when I interpolate Serna to the dimensions of first_model (to lower resolution), it works perfectly fine. I don't know what I'm doing wrong.
I have attached the data
Any help is appreciated.
Thanks!
Melissa

Best Answer

There is a major discontinuity in the middle of the longitude data, that makes interpolation impossible. Lets find it:
>> median(diff(lat_model))
ans =
0.9424
>> all(0<diff(lat_model)) % this is monotonic, so no problem
ans =
1
>> median(diff(lon_model))
ans =
1.2500
>> all(0>diff(lon_model)) % not monotonic!
ans =
0
>> tmp = diff(lon_model);
>> find(tmp<0) % lets find where...
ans =
145
>> lon_model(140:150) % and the data looks like this:
ans =
173.7500
175.0000
176.2500
177.5000
178.7500
180.0000
-178.7500
-177.5000
-176.2500
-175.0000
-173.7500
Wow... it jumps from +180 to -178.75, in the middle of a monotonic increasing sequence.
How to deal with this is up to you, and depends on what the data represents. If these are degrees you may be able to convert them to the positive equivalents:
idx = lon_model<0;
lon_model(idx) = 360 + lon_model(idx);
You should also remove that transpose from first_model, which will cause another error. This code works without error:
load data
idx = lon_model<0;
lon_model(idx) = 360 + lon_model(idx);
[X, Y] = meshgrid(lat_model, lon_model); %first_model coordinates
[Xq, Yq] = meshgrid(lat, lon); %Serna coordinates
Serna_approx = interp2(X, Y, first_model, Xq, Yq);
although this is not proof that it does what want it too