Interpolating over a grid
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Christian Mathiesen
am 7 Nov. 2021
Kommentiert: Christian Mathiesen
am 7 Nov. 2021
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);
0 Kommentare
Akzeptierte Antwort
Chunru
am 7 Nov. 2021
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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!