How to take a horizontal slice of a 3D Surface plot?
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 3 Nov 2019
If you had an array of x, y, z values, then
contour(x, y, z, [0.25 0.25])
would result in a contour at only 0.25 level.
Johan Mihindukulasuriya
le 3 Nov 2019
Modifié(e) : Johan Mihindukulasuriya
le 3 Nov 2019
Walter Roberson
le 3 Nov 2019
You have vectors of values, not arrays of values. You would use something like griddedInterpolant to create arrays of z values.
Johan Mihindukulasuriya
le 3 Nov 2019
Walter Roberson
le 3 Nov 2019
Johan Mihindukulasuriya
le 3 Nov 2019
Walter Roberson
le 3 Nov 2019
Modifié(e) : Walter Roberson
le 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])
Réponses (0)
Catégories
En savoir plus sur Surface and Mesh Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
