How do I do two animated lines in two different figures?

Hi everyone. I need to do two different animated figures, but it turns out that I can only make up a single plot with two animated lines. Is there any solution to this problem? For example I tried couple different methods, but none of them worked:
clear all
close all
clc
[figure(1),figure(2)]=deal(animatedline);
x=0:1000;
y1=0:2:2000;
y2=0:4:4000;
for k=1:length(x)
addpoints(figure(1),x(k),y1(k));
axis([0,1000,0,2000]);
drawnow
end
for k=1:length(x)
addpoints(figure(2),x(k),y2(k));
axis([0,1000,0,4000]);
drawnow
end
The one above gives me both lines animated, one after another, but still in the same figure.
This 2nd one draws at the same moment:
clear all
close all
clc
h=animatedline
b=animatedline
x=1:1000;
y1=2:2:2000;
y2=4:4:4000;
for k=1:length(x)
addpoints(h,x(k),y1(k));
addpoints(b,x(k),y2(k));
drawnow
end
And the 3rd one goes crazy at all:
clear all
close all
clc
[figure(1),figure(2)]=deal(animatedline);
x=1:1000;
y1=2:2:2000;
y2=4:4:4000;
for k=1:length(x)
addpoints(figure(1),x(k),y1(k));
addpoints(figure(2),x(k),y2(k));
drawnow
end
The last one connects both lines and makes up one polyline. How can I avoid these problems? Is there any way I can make two different figures? And why is it when I assign h and b to be animatedline separately, it gives me two proper lines, whereas when I use [h,b]=deal(animatedline) function it gives me polyline? Thanks in advance!

 採用された回答

Adam
Adam 2016 年 7 月 11 日

0 投票

Did you look at the documentation for animatedline? Like all plotting functions it allows you to specify an axes on which to plot, which I strongly recommend doing in all usage other than quick command line testing.
h = animatedline(ax,___)
is the relevant documentation line so simply
figure; hAxes(1) = gca;
hAnimatedLine(1) = animatedline( hAxes(1),... )
figure; hAxes(2) = gca;
hAnimatedLine(2) = animatedline( hAxes(2),... )
will give you two animated lines on two different figures. Equally you could create 2 distinct axes on the same figure and plot to those.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeAnimation についてさらに検索

質問済み:

2016 年 7 月 11 日

回答済み:

2016 年 7 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by