Clear Filters
Clear Filters

Using Interp 2 to regrid multiple sets of Lat Long data

21 views (last 30 days)
I am using a lot of annual averages of climate data that comes from 5 different models. 3 of the 5 models use the same grid, while the other 2 have unique grids. Per other questions on here, I have made sure all my initial values are postitive and continuous. To limit the amount of data manuiulation and uncertainity, I am okay with using the "nearest" interpolation method and having a final grid that is more course. I am getting the following error:
Error using griddedInterpolant
Sample points must be sorted in ascending order.
I adjusted the sample dimensions so that they were ascending (the long values before started at 72.5 went to 360 and the jumped to 0.6 and then continued assending) and made your the sample data adjusted as well to match. I still got the same error so I am assuming that is is the actual sample matrix that has to be assending. I have tried switching the sample matrix to a single column but get an error stating the sample value must have 2 dimensions (or something like that, i cleared my command history - but by leaving it as a matrix seemed to resolve that issue).
My script is below and I've attached the work space variables. The end goal is to have a destination grid that i can map all 5 of the models data onto.
Any help or suggestions is appreciated!
%comGridder2 - script to adjust existing vars all to common grid
clear
%load in variables
load sl126crnt.mat
SLlat = ncread("ecSL126\SL126ecF5.nc", "latitude");
SLlong = ncread("ecSL126\SL126ecF5.nc", "longitude");
%put Vars in vectors & and in proper form for interp2
%(remove duplicates at end of dimensions)
SLvar = sl126crnt;
SLvar(:,292)=[];
SLvar([361,362],:)=[];
%adjust lats to be all postive and be on correct dimension
SLlatpos=SLlat(1,:)+90;
SLvLat=SLlatpos(1,1:291);
%put longs in assending order
LngCut=SLlong(1:360,1);
SLvLong=zeros(360,1);
SLvLong(1:73)=LngCut(288:360,1);
SLvLong(74:360)=LngCut(1:287,1);
SLnanCHK = isnan(SLvar);
SLnonan=zeros(360,291);
zFill = randperm(104760,104760)+100000;
zFill =reshape(zFill,[360,291]);
for k= 1:360
for j=1:291
if SLnanCHK(k,j) == 0
SLnonan(k,j)= SLvar(k,j);
else
SLnonan(k,j)= zFill(k,j);
end
end
end
%Put vars in assending orded to match Longs above
SLvarADJ=zeros(360,291);
SLvarADJ(1:73,:)=SLnonan(288:360,:);
SLvarADJ(74:360,:)=SLnonan(1:287,:);
%build final grid 2
comLat=(0:.2:180);
comLong=(0:.2:360)';
%assign values to new grid
regridSL=interp2(SLvLat,SLvLong,SLvarADJ,comLat,comLong,"nearest",0);

Accepted Answer

Matt J
Matt J on 13 Oct 2022
Edited: Matt J on 13 Oct 2022
Your SLvLong data are non-monotonic.
>> SLvLong(270:280)
ans =
269.0615
270.0265
270.9909
271.9549
270.7897 %<---decrease
271.7916
272.7956
273.8017
274.8098
275.8201
276.8324

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!