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
  1 件のコメント
Olawale Ikuyajolu
Olawale Ikuyajolu 2020 年 5 月 12 日
Why not use CDO to regrid this data

サインインしてコメントする。

回答 (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 Center および File ExchangeInterpolation 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