Writing a plot into a video

41 次查看(过去 30 天)
Yanjika O
Yanjika O 2020-6-28
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
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);
Yanjika O
Yanjika O 2020-6-28
Wow, I wish I could be so easy as you to understand and correct this as needed. It was really helpful Thank you~

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2020-6-28

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by