How to regrid data based on longitude-latitude variables?

24 次查看(过去 30 天)
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

回答(2 个)

Olawale Ikuyajolu
Olawale Ikuyajolu 2020-5-12
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 个评论
Maurício Andrade
Maurício Andrade 2022-11-23
@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 2022-11-23
I do not know how tripolar data is represented? I would not expect you to be able to use interp2 to for tripolar data.

请先登录,再进行评论。


Bjorn Gustavsson
Bjorn Gustavsson 2020-5-12
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

类别

Help CenterFile Exchange 中查找有关 Interpolation of 2-D Selections in 3-D Grids 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by