Animated Line: display different colours and leave the colourful trail

8 Ansichten (letzte 30 Tage)
Butterflyfish
Butterflyfish am 15 Apr. 2020
Kommentiert: Adam Danz am 15 Apr. 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 Kommentar
Adam Danz
Adam Danz am 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')

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Animation finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by