Update:
After around 10 hours investigating this this issue, I have figured out a general solution for generating a gif animation at a fixed windows size:
1. in Matlab, fix the figure size. 2. in the for loop, save each single frame to a jpeg file (I use jpeg because it has the smallest size) 3. use another for loop to combine these jpeg files to a single gif animation by using imread and imwrite.
Why I use above routine? Because I find that getframe only captures the last subplot if the figure contains multiple subplots. I have tried getframe(gcf) with no success. This is really annoying!
Hopefully my solution works for others