MATLAB: Does MOVIE2AVI throw an error stating that it cannot open a file in MATLAB 7.6 (R2008a)

MATLAB

When I generate a movie matrix, F, and try to make an AVI file from it using MOVIE2AVI, I receive an error.
I generate the movie matrix using the code in the documentation for the MOVIE command and then call MOVIE2AVI:
Z = peaks; surf(Z);
axis tight
set(gca,'nextplot','replacechildren');
% Record the movie
for j = 1:20
surf(sin(2*pi*j/20)*Z,Z)
F(j) = getframe;
end
movie2avi(F,'mymovietest.avi')
I then receive an error stating that my file cannot be opened:
??? Error using ==> avi
Failed to open file.
Error in ==> avifile.avifile at 171
aviobj.FileHandle = avi('open',filename);
Error in ==> movie2avi at 63
avimov = avifile(filename,varargin{:});

Best Answer

Prior to execution of MOVIE2AVI, if the file 'mymovietest.avi' is open in any application, including MATLAB, the file cannot be written to by MOVIE2AVI. Close all applications that may be using the file and make sure that the file is not opened in MATLAB by issuing the command
clear mex
at the MATLAB workspace.