Plotting Lines and Points in 3D
显示 更早的评论
I need to learn how to plot lines and points in 3D. Can someone please provide an example in Matlab? Thank you.
采纳的回答
A = [1 -3 7];
B = [0 2 -6];
C = [0.5 -1 5];
% plot a line from A to B
v = [A; B];
plot3(v(:,1),v(:,2),v(:,3))
box on
grid on
xlabel('x')
ylabel('y')
zlabel('z')
% plot the point C
hold on
plot3(C(1),C(2),C(3),'o')

8 个评论
Thank you for troubling to answer: I come up with the following trying to create a drawing, but two of the lines aren't being shown. The ones that go to -1 on the Y axis. Can this be fixed to include the -1 on the Y axis? Is there a way to control the magnitude of the box that is being turned on? Is there a way to control the dimensions of the box that is turned on? Thanks.
A1 = [0 0 0];
A2 = [1 1 2];
A3 = [-1 1 2];
A4 = [1 -1 2];
A5 = [-1 -1 2];
% plot a line from A1 to AN
v = [A1; A2];
plot3(v(:,1),v(:,2),v(:,3))
box on
hold on
v = [A1; A3];
plot3(v(:,1),v(:,2),v(:,3))
hold on
v = [A1, A4];
plot3(v(:,1),v(:,2),v(:,3))
hold on
v = [A1, A5];
plot3(v(:,1),v(:,2),v(:,3))
hold on
box on
grid on
You're welcome!
The problem with the plots involving A4 and A5 is that you're horizontally concatenating instead of vertically concatenating, which makes v 1x6 instead of 2x3. When v is 1x6, doing plot3(v(:,1),v(:,2),v(:,3)) plots a single point instead of two points with a line in between.
A1 = [0 0 0];
A2 = [1 1 2];
A3 = [-1 1 2];
A4 = [1 -1 2];
A5 = [-1 -1 2];
% plot a line from A1 to AN
v = [A1; A2];
plot3(v(:,1),v(:,2),v(:,3))
hold on
v = [A1; A3];
plot3(v(:,1),v(:,2),v(:,3))
v = [A1; A4];
% ^ semicolon (not comma)
plot3(v(:,1),v(:,2),v(:,3))
v = [A1; A5];
% ^ semicolon (not comma)
plot3(v(:,1),v(:,2),v(:,3))
box on
grid on
You can control the axes limits (and thus the box around the axes) using xlim, ylim, and zlim, e.g.:
ylim([-1 2])

Thank you very much!
You're welcome! Any questions, let me know. Otherwise, please "Accept" this answer. Thanks!
Is there any command I can give to get MATLAB to draw this thing to scale? Thank you.
axis equal

The man with all the answers!
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Annotations 的更多信息
另请参阅
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
