Animated Line: display different colours and leave the colourful trail

조회 수: 12 (최근 30일)
Butterflyfish
Butterflyfish 2020년 4월 15일
댓글: Adam Danz 2020년 4월 15일
I have a trajectory which I would like to animate with the colour changing depending on a condition. Here is my script so far:
h = animatedline('MaximumNumPoints', 1000);
axis([0, 384, -402, 0])
h.Marker='.';
for k = 1: length(trajectories.pos_x)
if ismember(k, freezing_time)
h.Color = 'g';
addpoints(h,trajectories.pos_x(k),-trajectories.pos_y(k))
elseif ismember(k, swim_time)
h.Color = 'y';
addpoints(h,trajectories.pos_x(k),-trajectories.pos_y(k))
elseif ismember(k, fast_time)
h.Color = 'r';
addpoints(h,trajectories.pos_x(k),-trajectories.pos_y(k))
end
drawnow
end
The problem is that the whole line is changing colour at each marker (when needed) and the 'trail' doesn't hold the original colours. For example, when hitting a coordinates with condition 1, the whole line goes green, where I would only want that coordinate point to go green.
Many thanks for any help!
  댓글 수: 1
Adam Danz
Adam Danz 2020년 4월 15일
You probably can't use animatedLine if you want each line segement to have its own color.
Instead, you can plot each segment as a new line using
hold on % only once
plot([x0,x1],[y0,y1], '-','color', 'g')

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by