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.
댓글 수: 0
채택된 답변
KL
2017년 5월 23일
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
댓글 수: 0
추가 답변 (2개)
Steven Lord
2017년 5월 23일
Create an animatedline then addpoints to that animatedline each time you step through your for loop.
댓글 수: 1
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'.
참고 항목
카테고리
Help Center 및 File Exchange에서 Animation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!