Filter löschen
Filter löschen

Can you change the color of new points without changing the color of an entire line?

6 Ansichten (letzte 30 Tage)
This code is designed to plot the motion of the earth traveling around the sun. Every year I would like the color of the new points to change but leave the rest of the points the color they were plotted in.
%Plot
animationTime = 20;
h = animatedline('color','r')
for i = 1:length(X(:,1))
addpoints(h,X(i,1),X(i,2),X(i,3));
pause(animationTime/length(X(:,1)));
if j > round(length(t)/(tspan(2)/years))
h.Color = [randi(100)/100 randi(100)/100 randi(100)/100];
j = 0;
end
j = j + 1;
end
tspan is the timespan for ode45. Its defined in terms of year and is then converted to seconds when fed into ode45. I understand why the existing code alters the entire line but is there a way to only effect new points. Thank you.

Antworten (1)

Walter Roberson
Walter Roberson am 17 Feb. 2023
No. The underlying graphics object only stores a single line color, not one color per point or group of points. You would need to start a new animated line.

Kategorien

Mehr zu Animation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by