How to create a 2D line plot animation

8 visualizaciones (últimos 30 días)
Jimmy Neutron
Jimmy Neutron el 12 de En. de 2021
Respondida: Jimmy Neutron el 12 de En. de 2021
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);

Respuesta aceptada

Jimmy Neutron
Jimmy Neutron el 12 de En. de 2021
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);

Más respuestas (0)

Categorías

Más información sobre Animation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by