필터 지우기
필터 지우기

How to create a 2D line plot animation

조회 수: 15 (최근 30일)
Jimmy Neutron
Jimmy Neutron 2021년 1월 12일
답변: Jimmy Neutron 2021년 1월 12일
I have a double array of 2001 values which is recorded from SImulink in 20 seconds. When I try to create a video animation of the graph plotting, I get an output of 1:06 minutes. Is there a way to create an animation that would correlate to the original 20 seconds and save it as an mp4 file directly? Here is my code:
load("test1.mat");
video = VideoWriter('test1','MPEG-4');
open(video)
curve = animatedline('Color','r');
set(gca, 'XLim', [0 2001],'YLim', [-200 200])
grid on
for i=1:2001
addpoints(curve,i ,val(i));
drawnow
writeVideo(video,getframe(gcf));
end
close(video);

채택된 답변

Jimmy Neutron
Jimmy Neutron 2021년 1월 12일
It is a matter of frames per second - as the recording were done at a sample rate of 0.01, the fps was set to 100. Here is te code:
load("test1.mat");
video = VideoWriter('test1','MPEG-4');
video.FrameRate = 100;
open(video)
curve = animatedline('Color','r');
set(gca, 'XLim', [0 20],'YLim', [-200 200])
grid on
for i=1:2001
addpoints(curve,i*0.01 ,val(i));
drawnow
writeVideo(video,getframe(gcf));
end
close(video);

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by