MATLAB: Is it possible to close an AVI-file when I do not have a handle that refers to it

MATLAB

I created a function which opens an AVI-file using the following command:
mov = avifile('example.avi')
If for some reason the function terminates without closing the AVI-file as shown below, I would still like to be able to close the file.
mov = close(mov);

Best Answer

The ability to find open AVI-files is not available in MATLAB R2008a.
To workaround this issue, one can execute the following command
clear all
Note that this will clear all the variables present in the MATLAB workspace.
Another way to workaround this issue is by storing the handle to the AVI-file as an application-specific data. This can be done using SETAPPDATA as in the following example:
aviobj = avifile('test.avi');
setappdata(0, 'AviobjBackup', aviobj);
To close the figure, GETAPPDATA can be used to obtain the previously stored data:
aviobj = getappdata(0, 'AviobjBackup');
aviobj = close(aviobj);