Error with 3D interpolation: Interpolation requires at least two sample points for each grid dimension

61 次查看(过去 30 天)
I am trying to interpolate a 3D grid (sample file is attached) file, that has several 1D depth profiles (image attached). My goal is to generate an interpolated 3D volume from the grid. My code is as follows:
VsGrid = csvread('3d_Vs_utm_samplefile.csv');
X = VsGrid(:,1); % UTM X
Y = VsGrid(:,2); % UTM Y
Z = VsGrid(:,3); % Depth
V = VsGrid(:,4); % Shear wave velocity values
figure(1) % Display the imported data
scatter3(VsGrid(:,1), VsGrid(:,2), VsGrid(:,3), [], VsGrid(:,4), 'Marker', '.');
[Xq,Yq,Zq] = meshgrid(547151:100:550828,5402976:100:5405454,-2000:50:0); % Create a 3D mesh
Vq = interp3(X,Y,Z,V,Xq,Yq,Zq); % Interpolate the grid file
When I am running the above code, I am getting an error "Interpolation requires at least two sample points for each grid dimension". I have tried using different grid intervals for Xq, Yq and Zq, but nothing seems to work. Can someone please guide me through this?
Thank you.

采纳的回答

Torsten
Torsten 2023-10-31
编辑:Torsten 2023-11-1
VsGrid = csvread('3d_Vs_utm_samplefile.csv');
X = VsGrid(:,1); % UTM X
Y = VsGrid(:,2); % UTM Y
Z = VsGrid(:,3); % Depth
V = VsGrid(:,4); % Shear wave velocity values
F = scatteredInterpolant(X,Y,Z,V,'linear','nearest')
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
F =
scatteredInterpolant with properties: Points: [53489×3 double] Values: [53489×1 double] Method: 'linear' ExtrapolationMethod: 'nearest'
figure(1) % Display the imported data
scatter3(VsGrid(:,1), VsGrid(:,2), VsGrid(:,3), [], VsGrid(:,4), 'Marker', '.')
colorbar
Xmin = min(X)
Xmin = 5.4715e+05
Xmax = max(X)
Xmax = 5.5083e+05
Ymin = min(Y)
Ymin = 5.4030e+06
Ymax = max(Y)
Ymax = 5.4055e+06
Zmin = min(Z)
Zmin = -600
Zmax = max(Z)
Zmax = 0
[Xq,Yq,Zq] = meshgrid(linspace(Xmin,Xmax,50),linspace(Ymin,Ymax,50),linspace(Zmin,Zmax,50)); % Create a 3D mesh
Vq = F(Xq,Yq,Zq);
figure(2) % Display the interpolated/extrapolated data
scatter3(Xq(:), Yq(:), Zq(:), [], Vq(:), 'Marker', '.')
colorbar
  3 个评论
Torsten
Torsten 2023-11-1
I don't know what you mean by
"scatteredInterpolant" does interpolates, but it gives interpolated 3D scattered point file. There are no values between those points.
"scatteredInterpolant" gives interpolated values at the points that you prescribe.
Above, you prescribe that you want to have values for V on the brick grid
linspace(Xmin,Xmax,50) x linspace(Ymin,Ymax,50) x linspace(Zmin,Zmax,50)
and F(Xq,Yq,Zq) returns these values.
Hems
Hems 2023-11-1
编辑:Torsten 2023-11-1
Yes, you are correct. "scatteredInterpolant" does gives values at the query points, but I was looking for a function or a way that would give me intermediate values as well, escpecially to build some interpolated cross-cutting 2D sections. Having said that, your answer has helped me in getting a desired 3D volume for generating interpolated 2D slices. I have modified your code a little bit to do that, as follows:
%%Read 1D Vs profiles, display them and create a fine 3D meshgrid
VsGrid = csvread('3d_Vs_utm_samplefile.csv');
X = VsGrid(:,1); % UTM X
Y = VsGrid(:,2); % UTM Y
Z = VsGrid(:,3); % Depth
V = VsGrid(:,4); % Shear wave velocity values
figure(1) % Display the imported data
scatter3(VsGrid(:,1), VsGrid(:,2), VsGrid(:,3), [], VsGrid(:,4), 'Marker', '.');
colorbar;
% Range of grid values
Xmin = min(X);
Xmax = max(X);
Ymin = min(Y);
Ymax = max(Y);
Zmin = min(Z);
Zmax = max(Z);
%% Using function scatteredInterpolant
F1 = scatteredInterpolant(X,Y,Z,V,'linear','nearest');
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
[Xq1,Yq1,Zq1] = meshgrid(linspace(Xmin,Xmax,300),linspace(Ymin,Ymax,200),linspace(Zmin,Zmax,100)); % Create a 3D mesh
Vq1 = F1(Xq1,Yq1,Zq1);
%% Display the interpolated/extrapolated data using scatteredInterpolant
figure(2)
scatter3(Xq1(:), Yq1(:), Zq1(:), [], Vq1(:), 'Marker', '.');
colorbar;
%% Plot interpolated slices of the result
figure(3)
slice(Xq1,Yq1,Zq1,Vq1,[548000 550000],[5404000,5405000],[-2000,-250]);
shading flat;
colorbar;
Thank you very much for your help. Your code fulfills what I want to achieve with my data.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by