Borrar filtros
Borrar filtros

Plotting a 3D line on a surface plot

70 visualizaciones (últimos 30 días)
DONGUK KIM
DONGUK KIM el 23 de Mayo de 2020
Respondida: Apurvi Mansinghka el 18 de Jun. de 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 comentario
Walter Roberson
Walter Roberson el 23 de Mayo de 2020
view(3)
When hold is on, view(3) is not automatically called for 3d graphics.

Iniciar sesión para comentar.

Respuestas (1)

Apurvi Mansinghka
Apurvi Mansinghka el 18 de Jun. de 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

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by