Animated Line: display different colours and leave the colourful trail
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
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')
Réponses (0)
Voir également
Catégories
En savoir plus sur Animation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!