saving figures to a video with VideoWriter
48 ビュー (過去 30 日間)
古いコメントを表示
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");
obj.Quality = 100;
obj.FrameRate = 50;
open(obj);
for i=1:length(frames)
writeVideo(obj,frames{i})
end
obj.close();
0 件のコメント
採用された回答
Walter Roberson
2023 年 1 月 28 日
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Audio and Video Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!