Interpolating 3D Gridded Data in Matlab

조회 수: 5 (최근 30일)
Mark
Mark 2022년 11월 21일
댓글: Mark 2022년 11월 22일
I have a 3D gridded data and I want to interpolate to increase the size of the data. Current resolution is 5 deg long x 5 deg latitude and I want to change the resolution to 2 deg long x 2 deg latitude as I am interested in Lat = 2 deg. The dimension of the data is (Longitude x Latitude x Height) and current size is (72x36x40).
Long= 72x36x40
Lat = 72x36x40
Height =72x36x40
Temperature =72x36x40
I tried to use the interpn function but at the end I am only getting NaN values. Below are my codes.
file='data.nc';
Lat1 = ncread(file,'Latitude'); % Size is 72x36x40
Long1 = ncread(file1, 'Longitude'); % Size is 72x36x40
Height = ncread(file1,'Height'); % Size is 72x36x40
Temp1 = ncread(file,'Temperature'); % Size is 72x36x40
[LongI,LatI,HeightI] = ndgrid(0:5:360,-90:5:90,0:10:600);
TempI = interpn(Long1,Lat1,Height,Temp1,LongI,LatI,HeightI,'linear');`
My goal is to convert 3D data at 5 long x 5 lat resolution to 2 long x 2 lat resolution.

채택된 답변

Matt J
Matt J 2022년 11월 21일
편집: Matt J 2022년 11월 21일
This might be easier:
LUT= griddedInterpolant(Long1,Lat1,Height,Temp1,'linear','linear'); %create interp object
newgrid=LUT.GridVectors;
newgrid(1:2)=cellfun(@(z) z(1):2:z(end) , newgrid(1:2),'uni',0); %change the sampling lattice in the first two coordinates to be increments of 2
TempI = LUT(newgrid); %interpolate on newgrid
  댓글 수: 11
Matt J
Matt J 2022년 11월 22일
편집: Matt J 2022년 11월 22일
That was given in my original answer. After the upsampling to 2 long x 2 lat, the upsampled {long,lat,height} are in newgrid, while the upsampled temperatures are in TempQ.
Mark
Mark 2022년 11월 22일
Many thanks @Matt J.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by