Writing a plot into a video
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Walter Roberson
il 28 Giu 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);
Risposte (1)
Vedere anche
Categorie
Scopri di più su Annotations in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!