Plotting a 3D line on a surface plot
69 ビュー (過去 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!