Is it possible to take a cross section at different points of a 3-D plot?

11 views (last 30 days)
I have a script which when ran produces various 3 dimensional plots, I was wondering if there is any way to obtain a 2 dimensional plot for a given point along any of the axis?
Many thanks
C Boyce

Accepted Answer

Star Strider
Star Strider on 10 Apr 2015
If you want to see them parallel to the x or y axes it’s easy enough:
x = linspace(-2, 2, 25);
y = linspace(-pi, pi, 25);
[X,Y] = meshgrid(x,y);
Z = X.^2 + sin(Y);
figure(1)
surf(X, Y, Z)
grid on
iy = Y(X == 1);
iz = Z(X == 1);
figure(2)
plot(iy, iz)
grid on
title('Plot Z(Y,X=1)')
ix = X(Y == 3*pi/4);
iz = Z(Y == 3*pi/4);
figure(3)
plot(ix, iz)
grid on
title('Plot Z(X,Y=3*\pi/4)')
To see them at a particular value of z, use the contour function. To see them in any other orientation, use the slice function.
  2 Comments
C Boyce
C Boyce on 13 Apr 2015
Sorry it took me a while to get back to you.
Yes this worked brilliantly, thank you so much, and thanks for your quick answer.
Star Strider
Star Strider on 13 Apr 2015
No worries! We all have lives outside MATLAB Answers.
Thank you. My pleasure.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!