Draw the trail of a moving marker on an animated 2D plot

조회 수: 44 (최근 30일)
Jake
Jake 2020년 8월 5일
댓글: Jake 2020년 8월 5일
Hi everyone!
So, I'm creating a 2D plot where the marker moves from one point to another (nothing fancy, just pausing the plot). Code in question is something similar to this.
A = rand(1800,1);
B = rand(1800,1); % I'm just using dummy values here but my actual program has similar outputs (1800 x 1 double)
for i=1:1800
plot (A(i),B(i), 'd', 'MarkerSize', 5, 'MarkerFaceColor', 'k')
axis ([-10 10 -10 10])
pause (0.1)
end
What I'm trying to achieve now is, however, the trail of the marker. When the marker goes from point 1 to 2 (for instance) I want it to leave a trail. So at the end of the day, there will be a plotted graph. How can I approach this?
Also, I'd appreciate any pointers or easier methods for this than using a for loop, if there is one :)
Thanks in advance!

채택된 답변

KSSV
KSSV 2020년 8월 5일
편집: KSSV 2020년 8월 5일
A = rand(1800,1);
B = rand(1800,1); % I'm just using dummy values here but my actual program has similar outputs (1800 x 1 double)
for i=1:1800
plot (A(i),B(i), 'd', 'MarkerSize', 5, 'MarkerFaceColor', 'k')
hold on
plot(A(1:i),B(1:i),'r')
hold off
axis ([-10 10 -10 10])
pause (0.1)
end
  댓글 수: 3
KSSV
KSSV 2020년 8월 5일
You can use the function comet. This is good.
Jake
Jake 2020년 8월 5일
Ah yes. Just looked over the documentation and seems like that should be my option. Thanks!

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

추가 답변 (0개)

카테고리

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