MATLAB Answers

How to close the extra legend added by comet fun?

8 views (last 30 days)
ziyong han
ziyong han on 8 Mar 2019
Commented: KSSV on 8 Mar 2019
I use the comet fun to trace my simdata, however the comet fun added the extra legend data to my fig, see the attached fig that "data1, data2, data3" were added when animating.
How should I close the extra "data1, data2, data3" at the beginning of the animation? BTW, I know how to close it when the animation is finished.
Snipaste_2019-03-08_12-02-39.png

  0 Comments

Sign in to comment.

Accepted Answer

KSSV
KSSV on 8 Mar 2019
Edited: KSSV on 8 Mar 2019
x = 1:100 ;
y = rand(size(x)) ;
figure
h = plot(x,y) ;
hold on
comet(rand(size(x))) ;
legend(h,'one')

  4 Comments

Show 1 older comment
KSSV
KSSV on 8 Mar 2019
x1 = 1:100 ;
y1 = rand(size(x1)) ;
figure
h1 = plot(x1,y1) ;
hold on
y2 = rand(size(x1)) ;
h2 = plot(x1(1),y2(1)) ;
legend(h1,'one')
for i = 1:100
set(h2,'XData',x1(1:i),'YData',y2(1:i))
drawnow
end
ziyong han
ziyong han on 8 Mar 2019
thanks, it do solve the problem.
But compare to comet, it is slower in my simulation data more than 10000.
Is there a good way to achieve this by comet?
KSSV
KSSV on 8 Mar 2019
as of now to make the plot fast..you can run the loop by skipping some values...you need not to run for every point.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by