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
Walter Roberson
2020년 5월 23일
view(3)
When hold is on, view(3) is not automatically called for 3d graphics.
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!