Question with interp3

4 ビュー (過去 30 日間)
Trung Ngo
Trung Ngo 2019 年 5 月 31 日
回答済み: meghannmarie 2019 年 6 月 6 日
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

採用された回答

meghannmarie
meghannmarie 2019 年 6 月 1 日
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 件のコメント
meghannmarie
meghannmarie 2019 年 6 月 6 日
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 2019 年 6 月 6 日
Thank you so much for your help !!!

サインインしてコメントする。

その他の回答 (1 件)

meghannmarie
meghannmarie 2019 年 6 月 6 日
Your welcome!

カテゴリ

Help Center および File ExchangeLive Scripts and Functions についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by