Writing a plot into a video

58 vues (au cours des 30 derniers jours)
Yanjika O
Yanjika O le 28 Juin 2020
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 commentaires
Walter Roberson
Walter Roberson le 28 Juin 2020
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 le 28 Juin 2020
Wow, I wish I could be so easy as you to understand and correct this as needed. It was really helpful Thank you~

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 28 Juin 2020

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by