Disappear of z coordinate when plotting 3D

조회 수: 16 (최근 30일)
KD39
KD39 2019년 11월 10일
답변: Image Analyst 2019년 11월 10일
Hi,
When I use figure and hold on with a for loop to plot a 3D plot, the z coordinate component always disappears which means the plot becomes 2D. Could anyone help the solve the issue? Thanks in advance. The folloing is the general code.
figure();
for index=1:max_val_1
other_code_here.....
for i=1:max_val_2
other_code_here.....
plot3(edge(i,1),edge(i,2),edge(i,3), 'o');
xlabel('x')
xlim([min max])
ylabel('y')
ylim([min max])
zlabel('z')
zlim([min max])
end
grid on
hold on
end

답변 (2개)

the cyclist
the cyclist 2019년 11월 10일
I think you can "manually" fix this by setting the view. For example, try
view(15,15)
after the plot is made.
I've seen a couple questions like this lately, so I'm wondering if there is some kind of bug with MATLAB defaulting to the "2-D" view (i.e. directly from "above", along the z-axis) when it should not be. I haven't been able to pin it down exactly enough for a bug report, though.
  댓글 수: 2
KD39
KD39 2019년 11월 10일
Hi the cyclist,
Thanks for your reply. Also I just discovered that if I move the hold on right after the plot3 statement only the first 'index' loop is plotted. The rest of the for loop 'index' won't be plotted.
This might be MATLAB bug but not sure.
Regards
the cyclist
the cyclist 2019년 11월 10일
I think you probably want the hold on statement immediately after the figure command (assuming your goal is to show every plot in that figure window). See the documentation for hold for the details.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2019년 11월 10일
Since you're plotting only a single point with each call to
plot3(edge(i,1),edge(i,2),edge(i,3), 'o');
you should place "hold on" inside that inner loop. And it should plot all max_val_2 points. Note that there is no reference to "index" inside your "i" loop so you should not expect anything different unless the badly-named "edge" vector changes within the outer "index" loop. By the way, edge(), min(), and max() are the names of a built-in functions so you don't want to use those as the names of your variable.
It's not a bug - it's a feature.bmp

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by