All of the matlab figure to animated GIF codes on the matlab file exchange that I have tested so far will work for Matlab version 18.104.22.1689 (R2010a) but not for Matlab version 22.214.171.1245 (R2011a). Two examples are http://www.mathworks.com/matlabcentral/fileexchange/21944-animated-gif and http://www.mathworks.com/matlabcentral/fileexchange/21407-gifaddframe. I have the Image Processing Toolbox for the 2011 version but not the 2010 version. Any suggestions?
Thank you Walter Roberson! I added the line
It fixed the problem for R2011
You need a pause(0.02) before getframe.
A drawnow is not enough. With pause(0.01) there are still some dropouts, but less, while I did not observe any problem with 0.02 seconds on a Core2Duo Win7/64 even under high system load.
When this does not help, and there are some Matlab/Java/OS combinations which worked better, but not perfect, with pause(0.1), try this:
fig_Paperposmode = get(aFigH, 'PaperPositionMode'); fig_PaperOrient = get(aFigH, 'PaperOrientation'); fig_Invhardcopy = get(aFigH, 'InvertHardcopy'); set(aFigH, ... 'PaperPositionMode', 'auto', ... 'PaperOrientation', 'portrait', ... 'InvertHardcopy', 'off');
print(aFigH, '-dpng', '-r0', FileName);
% Restore properties of the original image: set(aFigH, ... 'InvertHardcopy', fig_Invhardcopy, ... 'PaperPositionMode', fig_Paperposmode, ... 'PaperOrientation', fig_PaperOrient);