GIF:
gifname='example.gif';
frame=getframe(gcf);
im=frame2im(frame);
[I,map]=rgb2ind(im,20);
Ngif=1;
if Ngif==1
imwrite(I,map,gifname,'gif', 'Loopcount',inf,'DelayTime',1);%第一次必须创建!
else
imwrite(I,map,gifname,'gif','WriteMode','append','DelayTime',1);
end
Ngif=Ngif+1;
fclose all;
AVI:
aviobj=VideoWriter('example.avi');
open(aviobj);
frame=getframe(gcf);
writeVideo(aviobj,frame);
close(aviobj)