How to interpolate gridded data for a specific point

조회 수: 4 (최근 30일)
Ebtesam Farid
Ebtesam Farid 2020년 5월 19일
댓글: Ameer Hamza 2020년 5월 19일
I have a meteorological netcdf file contains (Geopotential heigh z, air-temperauter t, Specific Humidity q, Relative Humidity r) over North America with grid 0.75 x 0.75 resolution, and I want to get theses parameters over some stations with specific (latitude/longitude) so I tried to interpolate the gridded data, I used interp2 function but when I run my program I get an error message
folder = 'C:\New folder\';
f_name = '01_2016.nc';
data =[];
file = sprintf('%s%s',folder,f_name);
info = ncinfo(file);
Conventions = ncreadatt(file,'/','Conventions');
history = ncreadatt(file,'/','history');
longitude = ncread(file,'longitude');
latitude = ncread(file,'latitude');
level = ncread(file,'level');
time = ncread(file,'time');
z = ncread(file,'z');
t = ncread(file,'t');
q = ncread(file,'q');
r = ncread(file,'r');
size(z)
% to get a portion of q at lat/long
[lonref,latref] = meshgrid(longitude(:),latitude(:));
for i = 1:length(level)
q2d = q(:,:,i,1);
qlatlon(i) = interp2(lonref(:),latref(:),q2d(:),longitude,latitude); % Note this assumes that q is organized lon/lat/altitude/time,% if it is lat/lon/altitude/time, switch lat and lon in this expression
end
plot(qlatlon,levels) % Single profile for the first time at lat/lon
the error message I get is
[Error in interp2 (line 128)
F = makegriddedinterp({X, Y}, V, method,extrap);
Error in read_cn (line 26)
qlatlon(i) = interp2(lonref(:),latref(:),q2d(:),longitude,latitude); ]
any help please to what's wrong or what's the best way to interpolate this gridded data
this is the link on google drive of the file just because it's big file netcdf file

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 5월 19일
Change the line inside for-loop to this
qlatlon{i} = interp2(lonref,latref,q2d.',longitude,latitude);
% replace longitude,latitude with the quey point, both should be of equal size
Also I used cell array because the output of interp2 can be a vector that cannot be assigned as an element of a numeric array.
  댓글 수: 2
Ebtesam Farid
Ebtesam Farid 2020년 5월 19일
it works, Thanks so much
Ameer Hamza
Ameer Hamza 2020년 5월 19일
I am glad to be of help.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by