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 Exchange에서 Animation에 대해 자세히 알아보기

태그

질문:

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