Special plot3 command in Matlab

조회 수: 11 (최근 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에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by