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

59 views (last 30 days)
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.

Accepted Answer

Torsten
Torsten on 31 Oct 2023
Edited: Torsten on 1 Nov 2023
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 Comments
Torsten
Torsten on 1 Nov 2023
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 on 1 Nov 2023
Edited: Torsten on 1 Nov 2023
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!