How to create a 2D line plot animation

9 vues (au cours des 30 derniers jours)
Jimmy Neutron
Jimmy Neutron le 12 Jan 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);

Réponse acceptée

Jimmy Neutron
Jimmy Neutron le 12 Jan 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);

Plus de réponses (0)

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by