Plotting a 3D line on a surface plot

100 views (last 30 days)
DONGUK KIM
DONGUK KIM on 23 May 2020
Answered: Apurvi Mansinghka on 18 Jun 2020
I want to plot a 3D line
y = A.*((1+(9/4).*x).^(3/2)-1);
z = x.^(3/2);
on the surface
z = x.^(3/2);
so basically I want two plots one surface and other a line.
Here's the code that I wrote that doesn't return the result that I was looking for.
[X,Y] = meshgrid(0:0.1:30,1:30);
Z = X.^(3/2);
A = 8./(13.^(3./2)-8);
x = linspace(0,30,100);
y = A.*((1+(9/4).*x).^(3/2)-1);
z = x.^(3/2);
hold on
plot3(x,y,z)
surf(X,Y,Z)
hold off
When I run this it returns a 2D plot of a line and some random pixels.
Is there a way to make this code work?
Thanks.
  1 Comment
Walter Roberson
Walter Roberson on 23 May 2020
view(3)
When hold is on, view(3) is not automatically called for 3d graphics.

Sign in to comment.

Answers (1)

Apurvi Mansinghka
Apurvi Mansinghka on 18 Jun 2020
Hi,
I understand you want to plot multiple 3D objects on the same plot. In order to do so use the function view(dim) to specify line of sight for 3-D plots.
Modify the code as follows:
[X,Y] = meshgrid(0:0.1:30,1:30);
Z = X.^(3/2);
A = 8./(13.^(3./2)-8);
x = linspace(0,30,100);
y = A.*((1+(9/4).*x).^(3/2)-1);
z = x.^(3/2);
view(3) % set dim=3 for 3-D plot
hold on
plot3(x,y,z)
surf(X,Y,Z)
hold off

Community Treasure Hunt

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

Start Hunting!