Interpolating over a grid

조회 수: 2 (최근 30일)
Christian Mathiesen
Christian Mathiesen 2021년 11월 7일
댓글: 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 CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by