Writing a plot into a video
31 次查看(过去 30 天)
显示 更早的评论
Hello all,
I have this code for generating plots with complete dark and green rectangular. I wanted to get the frames and save them into video. How do i do this?
clear all
clc
repeats=5;
x=[3 7 7 3];
y=[3 3 7 7];
plot(x,y);
set(gca,'color','k','XTick',[], 'YTick', [])
set(gcf, 'WindowState', 'maximized')
for k=1:repeats
fill(x,y,'k')
set(gca,'color','k')
ax=gca;
xlim([0 10]);
ylim([0 10]);
pause(5)
fill(x,y,'g')
set(gca,'color','k')
ax=gca;
xlim([0 10]);
ylim([0 10]);
pause(5)
F(k)=getframe(gcf);
end
close all
writerObj=VideoWriter('safeGreen.avi','Uncompressed AVI');
writerObj.FrameRate=30;
open(writerObj);
writeVideo(writerObj,F);
close(writerObj);
4 个评论
Walter Roberson
2020-6-28
I suspect that you want the frames you draw to last 5 seconds each upon display.
In order to do that at 30 fps, you would have to record 150 copies of the same frame.
Alternately, you can switch to 1/5 fps, like in the below code.
repeats=5;
x=[3 7 7 3];
y=[3 3 7 7];
plot(x,y);
set(gca,'color','k','XTick',[], 'YTick', [])
set(gcf, 'WindowState', 'maximized')
for k=1:2:repeats*2
fill(x,y,'k')
set(gca,'color','k')
ax=gca;
xlim([0 10]);
ylim([0 10]);
pause(1)
F(k)=getframe(gcf);
fill(x,y,'g')
set(gca,'color','k')
ax=gca;
xlim([0 10]);
ylim([0 10]);
pause(1)
F(k+1)=getframe(gcf);
end
close all
writerObj=VideoWriter('safeGreen.avi','Uncompressed AVI');
writerObj.FrameRate=1/5;
open(writerObj);
writeVideo(writerObj,F);
close(writerObj);
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!