Expert Answer:
:
Yes, imwrite
does support animated GIFs. Like for AVI videos, you grab frames via getframe
sequentially. Then pass them to imwrite
though for GIFs you have to convert them from RGB to a 256 colormap before. Like this:
for i = 1:nFrames
% draw stuff
frame = getframe(gcf);
img = frame2im(frame);
[img,cmap] = rgb2ind(img,256);
if i == 1
imwrite(img,cmap,'animation.gif','gif','LoopCount',Inf,'DelayTime',1);
else
imwrite(img,cmap,'animation.gif','gif','WriteMode','append','DelayTime',1);
end
end
Have a look at openExample('matlab/WriteAnimatedGIFExample')
and at doc imwrite
for more information.