Plot multiple points in a for loop

16 次查看(过去 30 天)
Hello everyone, I have a for loop which is plotting different points over a certain amount of time. Right now the previous point is removed when the next one is added, but i would like to keep the old points.
n=100
for i=1:n+1
plot(i,i,'r.','MarkerSize',10);
axis([0 110 0 110])
f(i) = getframe(gcf);
end
Hopefully someone can help me with that.

采纳的回答

KL
KL 2017-5-23
use hold
n=100
for i=1:n+1
plot(i,i,'r.','MarkerSize',10);
hold on
axis([0 110 0 110])
f(i) = getframe(gcf);
end
hold off

更多回答(2 个)

Steven Lord
Steven Lord 2017-5-23
Create an animatedline then addpoints to that animatedline each time you step through your for loop.
  1 个评论
Kasun Kariyawasam
Kasun Kariyawasam 2018-11-29
编辑:Kasun Kariyawasam 2018-11-29
Thanks @steven. This was a good solution. Using 'animatedline' rather than 'plot' later allowed me to add different colors and legend entries for each line, which would have been difficult with 'plot'.

请先登录,再进行评论。


Felix Kalscheuer
Felix Kalscheuer 2017-5-23
Wow that was easier than i thought, thank you!

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by