필터 지우기
필터 지우기

saving figures to a video with VideoWriter

조회 수: 33 (최근 30일)
Eyal Sasson
Eyal Sasson 2023년 1월 28일
댓글: Eyal Sasson 2023년 1월 29일
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();

채택된 답변

Walter Roberson
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 CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by