how to plot by looping

i would like to ask how to plot coordinate by looping
this is beause i have some "status" to be followed when plotting,
thus im using the loop to check the status (4th column) like below:-
if it equal to 1 the marker should be in -*
if it equal to 0 the marker should be in -o red color
if none of the above, it should draw line,
but i only got the marker type only, not the "else" part
how should i able to plot the line and different type of marker base on the status at the 4th column
cities6=[181 -12 70 2
56 -12 80 1
184 -12 90 2
185 -12 100 2
186 -12 110 2
187 -4 110 2
188 0 110 2
189 4 110 2
4 8 110 0];
xa6=cities6(:,2);
ya6=cities6(:,3);
noofcities6=cities6(:,1);
for s6=1:n6
status6=cities6(:,4);
labels6=cellstr(num2str(noofcities6(s6)));
if status6(s6) == 1,
plot(xa6(s6),ya6(s6),'-*');
text(xa6(s6),ya6(s6),labels6, 'VerticalAlignment','bottom','HorizontalAlignment','right');
hold on
end
if status6(s6) == 0,
plot(xa6(s6),ya6(s6),'-o','color','r');
text(xa6(s6),ya6(s6),labels6, 'VerticalAlignment','bottom','HorizontalAlignment','right','color','r');
hold on
else
plot(xa6(s6),ya6(s6),'-');
end
hold on
end
grid on
grid minor
Thank you.

 采纳的回答

Thorsten
Thorsten 2015-10-22
编辑:Thorsten 2015-10-22
The points are not visible because plot(xa6(s6),ya6(s6),'-'); just plots a single point that falls on the axis or the grid lines. Use
axis([-20 10 50 120])
grid off
or
plot(xa6(s6),ya6(s6),'x');

3 个评论

hi Thorsten, thanks for answering, i have tried your suggestion, i manage to plot the point but can't display the line connected between the points, i tried '-x' and grid off, it display x as marker, but no line.
You see no line because you plot only a single point in each plot command. To plot the line, use
plot(xa6, ya6, '-')
now i know why, thank you =)

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by