How can I fix legend in an animate plot 2D?

6 ビュー (過去 30 日間)
Giacomo Lucidi
Giacomo Lucidi 2016 年 11 月 20 日
編集済み: Adeel Yousuf 2020 年 1 月 28 日
figure(1)
for j = 1:length(t)
plot(x,u(:,j),x,v(j,:),x,LF(j,:))
pause(0.1)
end
I would see the legend also the animate is running. Not only at the end of this. Thanks all.

採用された回答

KSSV
KSSV 2016 年 11 月 21 日
編集済み: KSSV 2016 年 11 月 21 日
clc; clear all ;
x = linspace(-2*pi,2*pi);
y1 = sin(x);
y2 = cos(x);
for i = 1:100
plot(x,rand(1)*y1,'r',x,rand(1)*y2,'b')
legend('sin(x)','cos(x)')
pause(0.1)
drawnow
end
  1 件のコメント
Giacomo Lucidi
Giacomo Lucidi 2016 年 12 月 10 日
Thanks!!!!

サインインしてコメントする。

その他の回答 (1 件)

Adeel Yousuf
Adeel Yousuf 2020 年 1 月 28 日
編集済み: Adeel Yousuf 2020 年 1 月 28 日
Not specific to your query but related to it... if some reader wants to animate the legend with every data point, then following code works with a little modification to @KSSV code. (...can be repeated for multiple vectors & likewise legends):
x = linspace(-2*pi,2*pi);
y1 = sin(x);
for i = 1:20
plot(x,rand(1)*y1,'r');
legend("sin(" + num2str(x(i))+")");
pause(0.1);
drawnow;
end

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by