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
KSSV 2020 年 8 月 3 日
Read about Comet
Nur Amalina
Nur Amalina 2020 年 8 月 3 日
Thanks @Kssv. i've tried comet but it doesn't work for multiple trajectory.
comet(x1(1,:),x2(1,:),x1(2,:),x2(2,:))
error: Too many input arguments.
jonas
jonas 2020 年 8 月 3 日
I dont understand what you want to do. Do you want to animate six or two lines?
Nur Amalina
Nur Amalina 2020 年 8 月 4 日
6 lines @jonas. i was trying to make 2 lines first but it didn't work

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

回答 (1 件)

Cris LaPierre
Cris LaPierre 2020 年 8 月 3 日
編集済み: Cris LaPierre 2020 年 8 月 3 日

0 投票

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 ExchangeAnimation についてさらに検索

タグ

質問済み:

2020 年 8 月 3 日

コメント済み:

2020 年 8 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by