MATLAB: Do I receive ‘Error using ==> avifile.ad​dframe>Val​idateFrame​’ when adding a frame to the avi file

avifileMATLAB

I have created an avifile in MATLAB 7.0.1 (R14SP1) using the AVIFILE function shown in the code below:
mov = avifile('fn6.avi');
figure
line
mov = addframe(mov,gcf);
pause
mov = addframe(mov,gcf);
mov = close(mov);
I create a plot and begin to add frames to the movie. If I move the figure around the window I will receive the following error even though the size of the figure has not changed.
Error using ==> avifile.addframe>ValidateFrame
Frame must be 560 by 421.

Best Answer

The proper way to add frames to a movie is as described in the documentation, to add frames to the avifile by using the GETFRAME function as shown in the code below:
mov = avifile('pd3.avi');
figure
surf(peaks)
frame = getframe(gcf);
mov = addframe(mov,frame);
frame = getframe(gcf);
mov = addframe(mov,frame);
mov = close(mov);
Note that MATLAB graphics objects must be displayed on screen because the GETFRAME function, which is used to produce frames for the movie structure, performs a screen capture to acquire the necessary image data for the frames.
Related Question