Error with 3D interpolation: Interpolation requires at least two sample points for each grid dimension
59 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
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')
figure(1) % Display the imported data
scatter3(VsGrid(:,1), VsGrid(:,2), VsGrid(:,3), [], VsGrid(:,4), 'Marker', '.')
colorbar
Xmin = min(X)
Xmax = max(X)
Ymin = min(Y)
Ymax = max(Y)
Zmin = min(Z)
Zmax = max(Z)
[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
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.
More Answers (0)
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!