Special plot3 command in Matlab

2 次查看(过去 30 天)
mr mo
mr mo 2017-12-2
评论: mr mo 2017-12-10
Hi. I have a matrix named S, e.g.
S =
[25 4 14
26 4 14
27 4 14
28 4 14
29 4 14
30 4 14
31 4 14
32 4 14
33 4 14];
Every row in matrix S indicates a point in 3D space. I want to use plot3 command to plot these points.
plot3(S(:,1),S(:,2),S(:,3),'s')
This code plots these points with squares, but I want to have cubes instead of squares. How can I do that?
Thanks.

采纳的回答

Jan
Jan 2017-12-2
As you can find the in the documentation of plot3, or to be exact at the link to "line properties", cubes are not a recognized marker type. Then you have to draw them by your own.
It matters if you want the wireframe of the cube or filled patches.
See e.g. https://www.mathworks.com/matlabcentral/fileexchange/15161-plotcube or http://jialunliu.com/how-to-use-matlab-to-plot-3d-cubes/ (I magically found these links by asking an internet search engine for the terms "Matlab draw cube" - you can do this by your own also.)
  8 个评论
Jan
Jan 2017-12-10
@mr mo: The link in your former comment is dead now. For which function are you searching a legend? Did you try to provide one handle per legend entry? The plotcube command would need to add an output of the handles. But I would take this code as example only, how to call patch. E.g.:
side = 5;
verts = ([0 0 0;0 1 0;1 1 0;1 0 0;0 0 1;0 1 1;1 1 1;1 0 1] - 0.5) .* side;
face = [1 2 3 4;5 6 7 8;3 4 8 7;1 2 6 5;2 3 7 6;1 4 8 5];
h1 = patch('Faces',face,'Vertices',verts,'FaceColor','b', ...
'EdgeColor','w');
h2 = patch('Faces',face,'Vertices',verts + 8,'FaceColor','g', ...
'EdgeColor','k');
legend([h1, h2], {'1', '2'})
view(45, 30)
grid on
mr mo
mr mo 2017-12-10
Thanks a lot. I want to add legend to plotcube function.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by