Can you change the color of new points without changing the color of an entire line?
조회 수: 6 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
Walter Roberson
2023년 2월 17일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Animation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!