How do I do two animated lines in two different figures?
Show older comments
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!
Accepted Answer
More Answers (0)
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!