How to interpolate gridded data for a specific point

2 visualizaciones (últimos 30 días)
Ebtesam Farid
Ebtesam Farid el 19 de Mayo de 2020
Comentada: Ameer Hamza el 19 de Mayo de 2020
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

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 19 de Mayo de 2020
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 comentarios
Ebtesam Farid
Ebtesam Farid el 19 de Mayo de 2020
it works, Thanks so much
Ameer Hamza
Ameer Hamza el 19 de Mayo de 2020
I am glad to be of help.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by