How to regrid data based on longitude-latitude variables?

22 Ansichten (letzte 30 Tage)
Keegan Carvalho
Keegan Carvalho am 12 Mai 2020
Kommentiert: Walter Roberson am 23 Nov. 2022
Hey Matlab world!
I am trying to regrid the data (file attached "air") from a 2.5 by 2.5 grid to a 0.5 by 0.5 grid of a 3d matrix ("air"). The air variable is characterized as lon x lat x time (144 x 73 x 72). So I wanted to change the longitude and latitude resolution without affecting the time variable i.e. from 144 x 73 x 72 -to- 721 x 361 x 72.
I did try interp2 and still get an error "Index in position 3 exceeds array bounds (must not exceed 72)".
Here's the code I have used thus far:
lon=ncread('air.nc','lon');
lat=ncread('air.nc','lat');
time=ncread('air.nc','time');
air=ncread('air.nc','air');
ox=0:0.5:360;
oy=-90:0.5:90;
new=interp2(lon,lat,air(:,:,time),ox,oy);
This might be a silly problem, but I can't seem to understand the error, since I am doing a 2d interpolation. Looking forward to your help

Antworten (2)

Olawale Ikuyajolu
Olawale Ikuyajolu am 12 Mai 2020
lon=ncread('air.nc','lon');
lat=ncread('air.nc','lat');
time=ncread('air.nc','time');
air=ncread('air.nc','air');
ox=[0:0.5:360-0.5]; %0 degrees and 360 degrees (180 east and west are the same). it is continuous
oy=[-90:0.5:90]';
for time = 1: size(air, 3) %loop through each time
new(:,:,time) =interp2(lon,lat,air(:,:,time)',ox,oy);
end
  13 Kommentare
Maurício Andrade
Maurício Andrade am 23 Nov. 2022
@Walter Roberson I would like to check out with you if possible if this command works well from tripolar to regular grid as well. I am struggling to find out information like this. Do you know if it works?
Walter Roberson
Walter Roberson am 23 Nov. 2022
I do not know how tripolar data is represented? I would not expect you to be able to use interp2 to for tripolar data.

Melden Sie sich an, um zu kommentieren.


Bjorn Gustavsson
Bjorn Gustavsson am 12 Mai 2020
First of all, your time-variable contains integers between 1411296 and 1463136, when you try to use those as indices you're looking for components in air way outside the size of that array. So you have to index with integers between 1 and 72. In my version of matlab this works fine:
new=interp2(lon,lat,air(:,:,1)',ox,oy')';
Where I had to transpose the oy to make interp2 happy.
HTH

Kategorien

Mehr zu Interpolation of 2-D Selections in 3-D Grids finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by