Interpolation problem between two 2D global datasets
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Melissa
el 15 de Mayo de 2015
Comentada: Walter Roberson
el 15 de Mayo de 2015
Hello,
I have two matrices I would like to compare.
First Matrix:
Serna (360x720)
lat (360x1)
lon (720x1)
Second Matrix:
first_model (288x192)
lat_model (192x1)
lon_model (288x1)
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
0 comentarios
Respuesta aceptada
Stephen23
el 15 de Mayo de 2015
Editada: Stephen23
el 15 de Mayo de 2015
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
2 comentarios
Walter Roberson
el 15 de Mayo de 2015
You need to unwrap the one that crosses 0, like I indicated before:
degrad = pi./180;
unwrappedBlong = unwrap(Blong .* degrad) ./ degrad;
For example, [177 178 180 -178 -177] unwraps to [177 178 180 182 183].
Más respuestas (0)
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!