saving figures to a video with VideoWriter

21 vues (au cours des 30 derniers jours)
Eyal Sasson
Eyal Sasson le 28 Jan 2023
Commenté : Eyal Sasson le 29 Jan 2023
when triyng to plot some data and save the figures to creat video file, i get this error:
i tried to debug the code and coulndnt find a way to fix it.
this is my code:
fs = 250;
t = 0:1/fs:3;
signal_freq = 0.5;
h1 = animatedline('Color','b','Linewidth',1.5);
h2 = animatedline('Color','r','Linewidth',1.5);
y = 180*sin(2*pi*signal_freq*t);
ycos = 180*cos(2*pi*signal_freq*t);
frames = cell(length(t),250/5);
for i= 1:5:length(t)-4
tvec = t(i:i+4);
yvec = y(i:i+4);
ycosvec = ycos(i:i+4);
addpoints(h1,tvec,yvec);
addpoints(h2,tvec,ycosvec);
drawnow;
frames{i} = getframe(gcf);
xlim([0 max(t)+1]);
ylim([-200 200]);
legend("sin","cos");
grid on;
end
obj = VideoWriter("myvideo","MPEG-4");
The specified profile is not valid.
obj.Quality = 100;
obj.FrameRate = 50;
open(obj);
for i=1:length(frames)
writeVideo(obj,frames{i})
end
obj.close();

Réponse acceptée

Walter Roberson
Walter Roberson le 28 Jan 2023
getframe() with no options is not guaranteed to return the same size each time. In practice the size of an axes can vary by (if I recall correctly) up to 7 pixels, mostly depending on the labels. You do not xlim or ylim before looping adding points, so the tick locations are being dynamically changed as you go, and that affects the axes width.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by