animate 2d plot
显示 更早的评论
Hi, All!
Say i have 2 variable, x1 and x2. I wanna plot (x1, x2) and animate it over time. i've tried this code:
x = [1 2;2 1;3 1;1 2;2 1;3 2];
x1 = x(1:end,1);
x2 = x(1:end,2);
r=animatedline;
for t=1:1000
for i=1:6
x1(i,t+1)=x1(i,t)+3;
x2(i,t+1)=x2(i,t)+x1(i,t);
end
addpoints(r,x1(1,:),x2(1,:))
addpoints(r,x1(2,:),x2(2,:))
drawnow
end
But that's not what i meant. From code above, the first line move from (1,2) to (4,3) to (7,7).... the second line move from (2,1) to (5,3), to (8,8),...
till the figure show the movement of those 6 lines.
4 个评论
KSSV
2020-8-3
Read about Comet
Nur Amalina
2020-8-3
jonas
2020-8-3
I dont understand what you want to do. Do you want to animate six or two lines?
Nur Amalina
2020-8-4
回答(1 个)
Cris LaPierre
2020-8-3
编辑:Cris LaPierre
2020-8-3
Here's one way to do it following the instructions on the Line Animations documentation page. I reduced the number of points to 100.
x = [1 2 3 1 2 3];
y = [2 1 1 2 1 2];
l1 = animatedline;
l2 = animatedline;
l3 = animatedline;
l4 = animatedline;
l5 = animatedline;
l6 = animatedline;
axis([0 150 0 1500])
for t = 1:100
if t>1
x(t,:)=x(t-1,:)+3;
y(t,:)=y(t-1,:)+x(t,:);
end
addpoints(l1,x(t,1),y(t,1))
addpoints(l2,x(t,2),y(t,2))
addpoints(l3,x(t,3),y(t,3))
addpoints(l4,x(t,4),y(t,4))
addpoints(l5,x(t,5),y(t,5))
addpoints(l6,x(t,6),y(t,6))
drawnow limitrate
end
类别
在 帮助中心 和 File Exchange 中查找有关 Animation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!