How to regrid data based on longitude-latitude variables?

조회 수: 24 (최근 30일)
Keegan Carvalho
Keegan Carvalho 2020년 5월 12일
댓글: Walter Roberson 2022년 11월 23일
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