Interpolating over a grid

4 ビュー (過去 30 日間)
Christian Mathiesen
Christian Mathiesen 2021 年 11 月 7 日
Hello. I have a grid of x and y coordinates and I would like to interpolate some z values over this grid. The grid constitues an area of ocean, and the z values, d_sea, constitutes sea depth values in metres. The dataset seadepth_002536 is a line of known seadepth values. I would like to know the sea depth values of the entire [x,y] grid. I have tried using interp2 but I am getting errors. Any help is appreciated. Thanks.
tykkelse_002536 = load('tykkelse_002536.txt');
seadepth_002536 = load('seafloor_depth_002536.txt');
v_sea = 1500; %p-wave velocity of water
v_sed = 2000; %p-wave velocity of sediment
x = tykkelse_002536(:,1);
y = tykkelse_002536(:,2);
d = tykkelse_002536(:,3);
d = d .* v_sed;
x_sea = seadepth_002536(:,1);
y_sea = seadepth_002536(:,2);
d_sea = seadepth_002536(:,3);
[Uxz_sea,ia,ic] = unique([x_sea d_sea],'rows');
x_sea = Uxz_sea(:,1);
d_sea = Uxz_sea(:,2);
d_sea = d_sea .* v_sea;
dx = 20;
x_ax=min(x):dx:max(x);
y_ax=min(y):dx:max(y);
[xx,yy]=meshgrid(x_ax,y_ax);
zii = interp2(x_sea,y_sea,d_sea,xx,yy);
Error using griddedInterpolant
Interpolation requires at least two sample points for each grid dimension.

Error in interp2>makegriddedinterp (line 226)
F = griddedInterpolant(varargin{:});

Error in interp2 (line 126)
F = makegriddedinterp({X, Y}, V, method,extrap);

採用された回答

Chunru
Chunru 2021 年 11 月 7 日
Use scatteredInterpolant instead.
tykkelse_002536 = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/792574/tykkelse_002536.txt');
seadepth_002536 = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/792579/seafloor_depth_002536.txt');
v_sea = 1500; %p-wave velocity of water
v_sed = 2000; %p-wave velocity of sediment
x = tykkelse_002536(:,1);
y = tykkelse_002536(:,2);
d = tykkelse_002536(:,3);
d = d .* v_sed;
x_sea = seadepth_002536(:,1);
y_sea = seadepth_002536(:,2);
d_sea = seadepth_002536(:,3);
[Uxz_sea,ia,ic] = unique([x_sea d_sea],'rows');
x_sea = Uxz_sea(:,1);
d_sea = Uxz_sea(:,2);
d_sea = d_sea .* v_sea;
dx = 20;
x_ax=min(x):dx:max(x);
y_ax=min(y):dx:max(y);
[xx,yy]=meshgrid(x_ax,y_ax);
% zii = interp2(x_sea,y_sea,d_sea,xx,yy);
f = scatteredInterpolant(x_sea, y_sea, d_sea);
zii = f(xx, yy);
  1 件のコメント
Christian Mathiesen
Christian Mathiesen 2021 年 11 月 7 日
Excellent. Thanks a lot!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by