Clear Filters
Clear Filters

Regridding 3D data

18 views (last 30 days)
Mark
Mark on 22 Nov 2022
Commented: Mark on 22 Nov 2022
I have a 3D data with a dimension of Longitude x Latitude x Altitude with a size of 76x40x54. The resolution of the data is 5 degree longitude by 5 degree latitude. I would like to regrid my data to 2 degree longitude by 2 degree latitude. Also I would like my longitude data to vary from 0 to 360 with a increment of 2 degrees (i. e 0 2 4 6 .......356 358) and latitude data to vary from -90 to 90 with a increment of 2 degrees (i.e -90 -88 86 ...0...86 88 90). The altitude resolution will be same. Is it possible to convert all of the variables like Longitude, Latitude and Temperature. I tried to interpolate to regrid the data but I got an error.
Link for the data:shorturl.at/oQSU7
The matlab code:
file='3DALL_t021213_000000.nc';
Temp=ncread(file,'Temperature');
Lat=ncread(file,'Latitude')*180/pi;
Long=ncread(file,'Longitude')*180/pi;
Alt=ncread(file,'Altitude');
Alt = Alt(1,1,:),
Alt = permute(Alt,[1 3 2]);
[LongI,LatI,AltI] = ndgrid(0:2:360,-90:2:90,Alt);
TempI = interpn(Lat,Long,Alt, Temp,LongI,LatI,AltI,'linear');
I am getting this error.
Error using griddedInterpolant
Grid arrays must have NDGRID structure.
Error in interpn (line 151)
F = griddedInterpolant(X{:}, V, method,extrap);
Error in untitled (line 9)
TempI = interpn(Lat,Long,Alt, Temp,LongI,LatI,AltI,'linear');
  2 Comments
Mark
Mark on 22 Nov 2022
Hi @Matt J, here I am asking to obtain slightly different results. I have two data with different resolutions (5 long x 5 lat & 2.5 long x 2.5 lat). I would like to convert these data into common resolution (let's say 2 long x 2 long). Is it possible to obtain a resolution with same longitude and latitude variation (same start and end point with same increment). Both of the inteploated data should have Longitude of (0:2:360) and Latitude of (-90:2:90) same. In my previous post, the resolution is same but the start and end points are not same as a result longitude and latitude are not same. Can we specific the start and end point and fixed increment so that longitude and latitude remains same.

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 22 Nov 2022
I am not familiar with Mapping Toolbox requirements (I don’t have it so have no experience with it), so I’m not certain what special requirements may be necessary for your data.
However, it would likely be best to use ndgrid to re-grid the longitude and latitude (not altitude) and then interpolate the altitude. Use either griddedInterpolant or scatteredInterpolant, depending on which is more reliable. (I generally use scatteredInterpolant even for gridded data.)
.

Community Treasure Hunt

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

Start Hunting!