Error using  '  during Transpose 3D variable from .nc file (error: "Transpose on ND array is not defined. Use PERMUTE instead.")

Hi all,
I am trying to transpose data using ' (e.g. A=A') but its showing error "Transpose on ND array is not defined. Use PERMUTE instead.". Could anyone help me to fix the error? For the 3D data variable I have used the following code to interpolate and to solve the problem:
File='trmm.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;
RF=griddedInterpolant({lon,flip(lat),time},flip(rain,1));
newdata=RF({LN,LT,time});
The following error is showing during riddedInterpolant command:
Error using griddedInterpolant
The grid vectors must be strictly monotonically increasing.
## THIS IS THE DATA DETAILS ##
==============
Name Size Bytes Class Attributes
lat 252x1 2016 double
lon 317x1 2536 double
rain 317x252x4748 3034313856 double
time 4748x1 37984 double
=========

5 Comments

Is your goal to end up with a 252x317x4748 array?
What shows up for
issorted(lon)
issorted(lat)
issorted(time)
lon(1) < lon(2)
lat(1) < lat(2)
time(1) < time(2)
Hi Walter,
Here is the error is showing:
----------------------
issorted(lon)
issorted(lat)
issorted(time)
lon(1) < lon(2)
lat(1) < lat(2)
time(1) < time(2)
[LN,LT] = meshgrid(lon,lat) ;
rain(isinf(rain)|isnan(rain))=0;
RF=griddedInterpolant({lon,lat,time},rain);
newdata=RF({LT,LN,time});
---------------------------------
Error:
Error using griddedInterpolant/subsref
Grid vector is not properly defined.
Error in Data_Regrid (line 30)
newdata=RF({LT,LN,time});
Thanks
I needed to see the output of those issorted() and comparison calls .
Hi Walter,
You can get the details from the attachment. Please let me know if you need anything more.
Thanks.lat.jpg

Sign in to comment.

 Accepted Answer

I suspect you don't want to interpolate, but you just want to flip the first two dimensions. In that case you can just listen to the error message:
new_rain=permute(rain,[2 1 3]);

5 Comments

Hi Rik,
I want do Complex conjugate transpose i.e. new_rain=rain' of the .nc file. I have attached one sample data if you wanna try!
Hope to see the solution.
Thanks in advance.
Not working:
---------
B=real(A)-1i*imag(A);
------------------------
Actually I want to remove the time mean (ie the mean of each rows of A). I am using:
F = detrend(A' , 'constant')';
and then caltulate Covariance Matrix (inner product over space = covariance in time)
R = F * F';
Now how do I process the data?
You keep changing what you want. Do you want to interpolate your data to a new grid, calculate the complex conjugate, calculate the inner product, or something else?
The root of your problem seems to be that what you want doesn't work in 3D, but does in 2D. Can you write a complete example of what it is you want for a 2D example so we can try to help you extend that to 3D. Otherwise we'll keep going around in circles.
Sorry for late response!
The problem has been solved by using
new_rain=permute(rain,[2 1 3]);
and afterwords 'reshape' command.
Thnaks a lot!

Sign in to comment.

More Answers (1)

Hi Rik,
Yes!
There is few modification in the script:
-------------------------------------------------
File='trmm.2010.nc'
rf=double(ncread(File, 'rf'));
time=double(ncread(File, 'time'));
lon=double(ncread(File, 'lon'));
lat=double(ncread(File, 'lat'));
ds = 0.25 ;
LN = min(lon):ds:max(lon) ;
LT = min(lat):ds:max(lat) ;
[LN,LT] = meshgrid(LN,LT) ;
rain=rf;
rain(isinf(rain)|isnan(rain))=0;
RF=griddedInterpolant({lon,lat,time},rain);
newdata=RF({LT,LN,time});
-------------------------------------------
Now the error is
Error using griddedInterpolant/subsref
Grid vector is not properly defined.
Error in Data_Regrid (line 21)
newdata=RF({LT,LN,time});
Regards

Categories

Tags

Asked:

on 28 Jan 2020

Commented:

on 5 Feb 2020

Community Treasure Hunt

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

Start Hunting!