Animated Line: display different colours and leave the colourful trail

8 visualizzazioni (ultimi 30 giorni)
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 Commento
Adam Danz
Adam Danz il 15 Apr 2020
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')

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Animation in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by