Plotting a 3D line on a surface plot

70 次查看(过去 30 天)
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 个)

Apurvi Mansinghka
Apurvi Mansinghka 2020-6-18
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

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by