The problem is that due to the rotation of the graph the size of the axis changes, so you end up with a sequence of frames of different sizes. You can see this if you insert the lines
s = size(mov(k).cdata);
fprintf('%d %d\n', s(2), s(1))
within the loop, directly after you grabbed the frame by
mov(k) = getframe(gca);
The result is
435 344
435 343
435 343
436 342
435 343
435 343
435 343
435 343
435 343
435 343
435 343
435 343
435 343
435 343
435 343
435 343
435 343
435 343
435 343
435 343
Because the first frame has the size 435 x 344, movie2avi
expects the following frames to be of the same size – but they're not.
In order to fix this, you might want to set the axis size (& position) explicitly using set(gca, 'Position', [...])
. An easier workaround though is to grab the frame not from the axis, but from the figure. That is, instead of mov(k) = getframe(gca);
use
mov(k) = getframe(gcf);
The frames then have a uniform size of 560 x 420.
On my machine, the resulting avi has frames upside down. In order to fix this, too, you can additionally insert a line
mov(k).cdata = mov(k).cdata(end :-1: 1, :, :);
after grabbing the frame.
refered from http://stackoverflow.com/questions/18949050/movie2avi-how-to-fix-the-frame-size