How to take a horizontal slice of a 3D Surface plot?

60 views (last 30 days)
What I am presented is with 3 sets of data that are supposed to fit on the x,y,z axis and create a 3D plot with no predefined function relating all of them. I first created a surface fit with cubic interpolation to generate a piecewise cubic interpolant and then I plotted this on a 3D graph. Shown below is the code I used for that:
dataset = xlsread('3DSurfaceData.xlsx', 'Sheet1','A1:C101')
x3 = dataset(:,1);
y3 = dataset(:,2);
z3 = dataset(:,3);
sf = fit([x3,y3],z3,'cubicinterp');
plot(sf,[x3,y3],z3)
xlabel('x')
ylabel('y')
zlabel('z')
hold on
patch([51.1,51.1,51.2,51.2],[-154.05,-154.13,-154.13,-154.05],[0.25,0.25,0.25,0.25],'w','FaceAlpha',0.7);
plot(sf, 'Style', 'Contour');
However, what I want to do now is take a horizantal slice of the surface plot at z=0.25 (as visualized by the patch) and put that data on a 2D plot. Or alternatively create a 2D contour plot at that z-value.
I've succesfully created vertical slices by using the interp2 function to interpolate z-values along the slice by using the x and y values along that slice. But I need to know how to do that horizantally.
  7 Comments
Johan Mihindukulasuriya
Johan Mihindukulasuriya on 3 Nov 2019
That clears things up somewhat. However I am rather confused on what the M values are in your code:
F = griddedInterpolant(x, y, z, M);
Xv = linspace(min(x), max(x), 20);
Yv = linspace(min(y), max(y), 20);
Zv = linspace(min(z), max(z), 20);
[Xg,Yg, Zg] = ndgrid(Xv, Yv, Zv);
Mg = F(Xg, Yg, Zg)
Where does it come from and what values does it signify?
Walter Roberson
Walter Roberson on 3 Nov 2019
Edited: Walter Roberson on 3 Nov 2019
"I have a dataset containing the x,y,z points as seperate entries (each a size of 100043) and M (also 100043) as a seperate entry in the workspace. "
That particular user has a scattered volume dataset, with coordinates x, y, z, and associated value stored in M.
Your situation would probably use 2D, like
N = 50;
F = scatteredInterpolant(x, y, z);
Xv = linspace(min(x), max(x), N);
Yv = linspace(min(y), max(y), N);
[Xg,Yg] = ndgrid(Xv, Yv);
Zg = F(Xg, Yg);
contour(Xg, Yg, Zg, [0.25 0.25])

Sign in to comment.

Answers (0)

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!