How to interpolate gridded data for a specific point
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!