필터 지우기
필터 지우기

How to animate different plots at the same time using subplot, addpoints and animatedline?

조회 수: 7 (최근 30일)
I am trying to animate tow distinct graphics simultanneosly using addpoins ane subplot. The two graphics should shown side by side, that is, in different cells (separated by subplot) while are being animated. However, the graphics are shown toghether on the seme cell.
Cound anyone help me to sove this problem?
Attached is the result the code output.
That is the code I have used:
t = 0:pi/20:10*pi;
% First graphic
subplot(1,2,1)
y1 = sin(t);
plot(t,y1)
% second graphic
subplot(1,2,2)
y2= sin(t+pi/2);
plot(t,y2)
curve1 = animatedline('LineWidth', 2);
curve2 = animatedline('LineWidth', 2);
for i = 1: length(t)
addpoints(curve1, t(i), y1(i));
drawnow
addpoints(curve2, t(i), y2(i));
% head = scatter(t(i), y(i));
drawnow
pause(0.01);
% delete(head);
end

채택된 답변

Adriano Filippo Inno
Adriano Filippo Inno 2019년 4월 4일
If you don't want to plot a moving marker:
t = 0:pi/20:10*pi;
y1 = sin(t);
y2 = sin(t+pi/2);
subplot(1,2,1)
curve1 = animatedline('LineWidth', 2);
hold on
plot(t,y1);
subplot(1,2,2)
curve2 = animatedline('LineWidth', 2);
hold on
plot(t,y2);
for i = 1: length(t)
addpoints(curve1, t(i), y1(i));
addpoints(curve2, t(i), y2(i));
drawnow
end
  댓글 수: 1
Rafael Espírito Santo
Rafael Espírito Santo 2019년 4월 5일
Thank you very much indeed Adriano. I Really appreciate your code. It definitely helps to solve my problem.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Oghenetega Oguns
Oghenetega Oguns 2022년 6월 6일
Thanks. This works for me

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

태그

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by