Animated Line: display different colours and leave the colourful trail

8 vues (au cours des 30 derniers jours)
Butterflyfish
Butterflyfish le 15 Avr 2020
Commenté : Adam Danz le 15 Avr 2020
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 commentaire
Adam Danz
Adam Danz le 15 Avr 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')

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by