MATLAB: Do I receive the error “Failed to open file” when using the MOVIE2AVI function in MATLAB 6.5 (R13)

MATLAB

When I execute the following code:
moviefilename='moviename';
fh=figure(1);
for k=1:10
plot(1:k);
M(:,k)=getframe(fh);
end
movie2avi(M,moviefilename,...
'compression','none','fps',4);
I receive the following error:
??? Failed to open file.
Error in ==> D:\Applications\MATLAB6p5p1\toolbox\matlab\iofun\@avifile\private\avi.dll
Error in ==> D:\Applications\MATLAB6p5p1\toolbox\matlab\iofun\@avifile\avifile.m
On line 162 ==> aviobj.FileHandle = avi('open',filename);
Error in ==> D:\Applications\MATLAB6p5p1\toolbox\matlab\iofun\movie2avi.m
On line 66 ==> avimov = avifile(filename,varargin{:});
Error in ==> T:\1472259\mycode.m
On line 7 ==> movie2avi(M,moviefilename,'compression','none','fps',4);

Best Answer

If you are running a code that will overwrite an existing AVI file, then you may receive an error if the existing file is open in another application. You should close any other applications that may have the file open, and then execute your code.