how to solve the error'The grid must be created from grid vectors which are strictly monotonically increasing'.

3 views (last 30 days)
Sreeraj R
Sreeraj R on 15 Nov 2021
Commented: Sreeraj R on 15 Nov 2021
hey
i am trying to extrapolate a data from 5.5x3.5 km to 55x55 km resolution. however i keep on getting this error when i run the code. how do i solve this?
file=('D:\Sreeraj\Earthdata tropomi\New folder\S5P_OFFL_L2__NO2___01012021.nc');
% ncdisp(file)
y=ncread(file,'/PRODUCT/latitude');
x=ncread(file,'/PRODUCT/longitude');
lat=y(1,:)';
lon=x(:,1);
vcd=ncread(file,'/PRODUCT/nitrogendioxide_tropospheric_column');
troamf=ncread(file,'/PRODUCT/air_mass_factor_troposphere');
ak=ncread(file,'/PRODUCT/averaging_kernel');
scd=vcd.*troamf;
%resampling data
[X,Y]=meshgrid(lon,lat);
[X1,Y1]=meshgrid(lon(1):0.5:lon(end),lat(1):0.5:lat(end));
for i=1:34
v=interp2(X,Y,ak(:,:,i)',X1,Y1);
v1(:,:,i)=v;
end
Error using griddedInterpolant
The grid must be created from grid vectors which are strictly monotonically increasing.
Error in interp2>makegriddedinterp (line 228)
F = griddedInterpolant(varargin{:});
Error in interp2 (line 136)
F = makegriddedinterp(X, Y, V, method,extrap);

Answers (1)

KSSV
KSSV on 15 Nov 2021
You code needs lot of changes.
This line:
[X1,Y1]=meshgrid(lon(1):0.5:lon(end),lat(1):0.5:lat(end));
should be replaced with:
[X1,Y1]=meshgrid(lon(1):-0.5:lon(end),lat(1):0.5:lat(end));
And the interpolation line:
v=interp2(X,Y,ak(:,:,i)',X1,Y1);
Should be replaced with:
v=interp2(X,Y,squeeze(ak(i,:,:))',X1,Y1);
Note that, your data i.e. X, Y and ak are scattered data and you cannot use interp2 for this. You should use scatteredInterpolant or griddata.

Tags

Community Treasure Hunt

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

Start Hunting!