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 Center および File ExchangeNetCDF についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by