Animate line but show marker only on current point

조회 수: 16 (최근 30일)
Ben
Ben 2015년 9월 16일
댓글: Brendan Hamm 2015년 9월 17일
I have data that overlaps itself a lot, so we're animating it for visualization purposes:
h = animatedline('Color', 'b');
DELAY = 0.001;
for i = 1:size(mapped_pts, 1)
addpoints(h, mapped_pts(i, 1), mapped_pts(i, 2));
drawnow
% pause(DELAY)
end
This works, but after a bit the "head" of the line gets harder to pick out, since it's small. I tried adding 'Marker', 'o' to the animatedline parameters, but that leaves a marker at every data point. I'd like to have a marker only on the most recently plotted point. Is this possible?

채택된 답변

Steven Lord
Steven Lord 2015년 9월 16일
The COMET function does what you're looking for with respect to the marker, but it requires all the data to be specified when COMET is called. If that's okay for your application, that's what I'd use.

추가 답변 (1개)

Brendan Hamm
Brendan Hamm 2015년 9월 16일
There is a function comet which does exactly this. It does not however allow you to control the pausing. Your other option is to create and delete a marker at every step:
f = figure;
ax = axes;
hold on
h = animatedline('Color', 'b');
DELAY = 0.001;
p = plot(ax,mapped_pts(1, 1),mapped_pts(1, 2),'o');
for i = 1:size(mapped_pts, 1)
p.XData = mapped_pts(i, 1);
p.YData = mapped_pts(i, 2);
addpoints(h, mapped_pts(i, 1), mapped_pts(i, 2));
drawnow
pause(DELAY)
end
  댓글 수: 2
Ben
Ben 2015년 9월 16일
I can't change my "accepted answer", I guess, but I ended up going with this one so I don't have to muck around with changing a built-in function to control the speed. Thanks!
Brendan Hamm
Brendan Hamm 2015년 9월 17일
No Problem. I have used this method in the past to allow for more control.

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

카테고리

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