saving figures to a video with VideoWriter
35 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Eyal Sasson
el 28 de En. de 2023
Comentada: Eyal Sasson
el 29 de En. de 2023
when triyng to plot some data and save the figures to creat video file, i get this error:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1276555/image.jpeg)
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");
obj.Quality = 100;
obj.FrameRate = 50;
open(obj);
for i=1:length(frames)
writeVideo(obj,frames{i})
end
obj.close();
0 comentarios
Respuesta aceptada
Walter Roberson
el 28 de En. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Audio and Video Data 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!