how to solve Error using .' Transpose on ND array is not defined. Use PERMUTE instead. Error in interp2 (line 122) V = V.';?

Hello I want to regrid my netcdf file based on lat and lon from 0.5 to 1 degree. now I faced this error.
Can anyone help me? here is my code:
filename='precip.mon.total.v2018.nc';
ncdisp(filename)
lat = ncread(filename,'lat');
lon = ncread(filename,'lon');
precip = ncread(filename,'precip');
t = ncdateread(filename,'time');
ds = 0.25 ;
loni = min(lon):ds:max(lon) ;
lati = min(lat):ds:max(lat) ;
[Loni,Lati] = meshgrid(loni,lati) ;
size(lat)
size(lon)
size(precip)
newpreceip=interp2(lat, lon, precip, loni, lati)
and that is wath appears in my comand window:
Source:
C:\Users\Behzad\Desktop\precip.mon.total.v2018.nc
Format:
netcdf4_classic
Global Attributes:
Original_Source = 'http://www.dwd.de/en/FundE/Klima/KLIS/int/GPCC/GPCC.htm
is the webpage and the data is at ftp://ftp.dwd.de/pub/data/gpcc/download.html'
Reference = 'Users of the data sets are kindly requested to give feed back and to refer to GPCC publications on this webpage: http://www.dwd.de/bvbw/appmanager/bvbw/dwdwwwDesktop/?_nfpb=true&_pageLabel=_dwdwww_klima_umwelt_datenzentren_wzn&T12404518261141645246564gsbDocumentPath=Content%2FOeffentlichkeit%2FKU%2FKU4%2FKU42%2Fteaser__product__access.html&_state=maximized&_windowLabel=T12404518261141645246564&lastPageLabel=_dwdwww_klima_umwelt_datenzentren_wzn'
original_source = 'ftp://ftp-anon.dwd.de/pub/data/gpcc/html/fulldata_download.html'
Conventions = 'CF 1.0'
dataset_title = 'Global Precipitation Climatology Centre (GPCC)'
References = 'https://www.esrl.noaa.gov/psd/data/gridded/data.gpcc.html'
title = 'GPCC Full Data Reanalysis Version 2018 0.5x0.5 Monthly Total'
history = 'Created 09/2018 based on V2018 data obtained via ftp'
data_modified = '2019-03-12'
_NCProperties = 'version=2,netcdf=4.6.3,hdf5=1.10.5'
Dimensions:
lat = 360
lon = 720
nbnds = 2
time = 1512 (UNLIMITED)
Variables:
lat
Size: 360x1
Dimensions: lat
Datatype: single
Attributes:
long_name = 'Latitude'
units = 'degrees_north'
standard_name = 'latitude'
axis = 'Y'
coordinate_defines = 'point'
actual_range = [89.75 -89.75]
lon
Size: 720x1
Dimensions: lon
Datatype: single
Attributes:
long_name = 'Longitude'
units = 'degrees_east'
standard_name = 'longitude'
actual_range = [0.25 359.75]
axis = 'X'
coordinate_defines = 'point'
time
Size: 1512x1
Dimensions: time
Datatype: double
Attributes:
long_name = 'Time'
units = 'days since 1800-1-1 00:00:00'
delta_t = '0000-01-00 00:00:00'
avg_period = '0000-01-00 00:00:00'
standard_name = 'time'
axis = 'T'
coordinate_defines = 'start'
actual_range = [33237 79227]
precip
Size: 720x360x1512
Dimensions: lon,lat,time
Datatype: single
Attributes:
missing_value = -9.969209968386869e+36
units = 'mm'
var_desc = 'Precipitation'
level_desc = 'Surface'
parent_stat = 'Observations'
long_name = 'GPCC Monthly total of precipitation'
valid_range = [0 8000]
statistic = 'Total'
level = 'Surface'
actual_range = [0 4552.4302]
dataset = 'GPCC Precipitation 0.5degree V2018 Full Reanalysis'
ans =
360 1
ans =
720 1
ans =
720 360 1512
Error using .'
Transpose on ND array is not defined. Use PERMUTE instead.
Error in interp2 (line 122)
V = V.';
Error in test100 (line 25)
newpreceip=interp2(lat, lon, precip, loni, lati)

 Accepted Answer

Because precip is not a 2D array, interp2 is the wrong tool. One alternative:
F=griddedInterpolant({lat,lon,t},precip);
newpreceip=F({lati,loni,t});

11 Comments

Dear Matt J
Thank you for your answer. I use your suggestion but this error is appear:
Error using griddedInterpolant
Grid coordinates must be of the same type, single or double.
Error in test100 (line 40)
F=griddedInterpolant({lat,lon,t},precip);
Do you have any idea?
best regards
You should convert all your variables to double floats.
Dear Matt J
Thank you again for your nice cooperation. after I convert all variable to double this error was apear:
Error using griddedInterpolant
The grid vectors are not strictly monotonic increasing.
Error in test100 (line 50)
F=griddedInterpolant({lat,lon,t},precip);
How to fix this error?
clc
clear
format compact
close all
filename='precip.mon.total.v2018.nc';
ncdisp(filename)
lat = ncread(filename,'lat');
lon = ncread(filename,'lon');
precip = ncread(filename,'precip');
t = ncread(filename,'time');
lat=double(lat);
lon=double(lon);
precip=double(precip);
t=double(t);
index=find(precip==-9.969209968386869e+36);
precip(index)=nan;
ds = 0.25 ;
loni = min(lon):ds:max(lon) ;
lati = min(lat):ds:max(lat) ;
[Loni,Lati] = meshgrid(loni,lati) ;
[latgrid,longrid] = meshgrid(lat,lon);
size(lat)
size(lon)
size(precip)
%regrid data
F=griddedInterpolant({lat,lon,t},precip);
newpreceip=F({lati,loni,t});
'precip.mon.total.v2018.nc' does not appear to be attached for us to test with.
I notice that for lat,
actual_range = [89.75 -89.75]
Are the values in lat strictly decreasing through that range?
Dear Walter Roberson
thank you for your answer. yes lat values are decerasing. first is 89.75 and -89.75 is end, and 360 lat are in between this range. infact lat is 360*1 double. you can download netcdf file at this link below:
morever I attached lat variable in .m format for you to see it.
thank you again and waiting for you to answer.
best regards
But the error message has told you that they must be increasing. So, make the obvious adjustments:
F=griddedInterpolant({flip(lat),lon,t},flip(precip,1));
newpreceip=F({lati,loni,t});
Dear Matt J
Thank you again for your answer. after using this code I faced the error below:
Error using griddedInterpolant
The grid vectors do not define a grid of points that match the
given values.
Error in test100 (line 52)
F=griddedInterpolant({flip(lat),lon,t},flip(precip,1));
do you have any idea?
best regards
Dear Matt J
The output is:
>> whos lat lon t precip
Name Size Bytes Class Attributes
lat 360x1 2880 double
lon 720x1 5760 double
precip 720x360x1512 3135283200 double
t 1512x1 12096 double
the screenshot of workplace is also attached. thank you
This should solve it:
F=griddedInterpolant({lon,flip(lat),t},flip(precip,1));
newpreceip=F({loni,lati,t});
Dear Matt J
Thank you for your precious help.
This solved my problem.
Best Regards

Sign in to comment.

More Answers (1)

I followed your answer on mathwork but cannot solve my issue with data. Could you help me to fix the error? I have used the following code:
File='rf.1998.2010.nc'
rf=double(ncread(File, 'rf'));
time=double(ncread(File, 'time'));
lon=double(ncread(File, 'lon'));
rain=rf'
rain(isinf(rain)|isnan(rain))=0;
F=griddedInterpolant({lon,flip(lat),time},flip(rain,1));
The following error is showing:
Error using griddedInterpolant
The grid vectors must be strictly monotonically increasing.
==============
Name Size Bytes Class Attributes
lat 252x1 2016 double
lon 317x1 2536 double
rain 317x252x4748 3034313856 double
time 4748x1 37984 double
===============
Best Regards,
Soumik

3 Comments

Dear @Soumik Ghosh
I found that this error appears because of ascending order or descending order in lon or lat data. Check lat and lon and make sure both of them are ascending or descending.
Note that if lat is ascending and lon is descending you can use this:
ds = 1
lat = max(lat):-ds:min(lat); %if lat be in descending order
Good Luck
Behzad Navidi
Since this isn't an answer, the content should be merged with the separately posted question and then deleted.

Sign in to comment.

Asked:

BN
on 6 Oct 2019

Commented:

on 28 Jan 2020

Community Treasure Hunt

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

Start Hunting!