Question with interp3

4 vues (au cours des 30 derniers jours)
Trung Ngo
Trung Ngo le 31 Mai 2019
Hi all,
I got an error using interp3 as:
% Error using griddedInterpolant
% The grid vectors do not define a grid of points that match the given values.
My code is as:
addpath('nctoolbox-1.1.3');
load('matlab.mat')
setup_nctoolbox;
grib = ncgeodataset('2018_Jan.grib');
grib.variables;
grib.size('10_metre_U_wind_component_surface');
U_wind1 = grib.geovariable('10_metre_U_wind_component_surface');
grib.dimensions('10_metre_U_wind_component_surface');
size(U_wind1);
class(U_wind1);
U_wind = U_wind1.data(:, :, :);
U_wind = permute(U_wind,[2 3 1]);
U_wind = squeeze(double(U_wind));
U_wind = flipud(U_wind);
skip = length(U_wind)/2;
U_wind = circshift(U_wind,[0,skip]);
coords_latitude = -90:0.75:90;
coords_longitude = -180:0.75:179.25;
coords_lat = coords_latitude';
coords_lon = coords_longitude';
path_time_total_grib = path_time_total/6;
for i=1:size(path_lat_value,1)
for j=1:size(path_lat_value,2)
U_wind_route(i,j) = interp3(coords_lon,coords_lat,...
coords_time,U_wind,path_lon_value(i,j),path_lat_value(i,j),path_time_total_grib(i,j));
end
end
I also attach the path_lon_value, path_lat_value, path_time_total as matlab.mat and Grib file as this google drive link https://drive.google.com/open?id=1ifuEnEnSThdhsq6FHbUXDfy-DyhhB_Ba
Thank you for your help

Réponse acceptée

meghannmarie
meghannmarie le 1 Juin 2019
First error I saw was you were using lat/lon vectors that were 0.75 degree resolution where the wind data was 1 degree resolution. I instead read the lat/lon from the file to make sure the data matched the coordinates.
Next, the data's longitude range was 0:360 where the path longitude rage was -180:180. So I did the modulus of the longitude path data by 360 to fix that.
Lastly, you do not want to loop through data. Just do interp3 on complete dataset, much faster.
Try this:
addpath('nctoolbox-1.1.3');
load('matlab.mat')
setup_nctoolbox;
grib = ncgeodataset('2018_Jan.grib');
U_wind1 = grib.geovariable('10_metre_U_wind_component_surface');
U_wind = U_wind1.data(:, :, :);
U_wind = permute(U_wind,[2 3 1]);
time = grib.geovariable('time');
grib_time = double(time.data(:));
lat = grib.geovariable('lat');
grib_lat = double(lat.data(:));
lon = grib.geovariable('lon');
grib_lon = double(lon.data(:));
path_time_total_grib = path_time_total/6;
path_lon_value_grib = mod(path_lon_value,360);
U_wind_route = interp3( grib_lon,grib_lat,grib_time, U_wind,...
path_lon_value_grib,path_lat_value,path_time_total_grib);
  10 commentaires
meghannmarie
meghannmarie le 6 Juin 2019
That should be correct.
I didnt have the data to see that longitude is the second dimension. So use 2 as your first input into cat because you are concatonating along the second dimension, use U_wind as second because you are adding data to end of longitudes, and U_wind(:,1,:) as the third input because that is the 1st values for longitude (0°) which is same as 360°.
U_wind_0_360 = cat(2,U_wind,U_wind(:,1,:));
Trung Ngo
Trung Ngo le 6 Juin 2019
Thank you so much for your help !!!

Connectez-vous pour commenter.

Plus de réponses (1)

meghannmarie
meghannmarie le 6 Juin 2019
Your welcome!

Catégories

En savoir plus sur Live Scripts and Functions dans Help Center et File Exchange

Tags

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by