Programming |
Closing a File
When you finish reading or writing, use fclose
to close the file. For example, this line closes the file associated with file identifier fid
:
This line closes all open files:
Both forms return 0
if the file or files were successfully closed or -1
if the attempt was unsuccessful.
MATLAB automatically closes all open files when you exit from MATLAB. It is still good practice, however, to close a file explicitly with fclose
when you are finished using it. Not doing so can unnecessarily drain system resources.
Note
Closing a file does not clear the file identifier variable fid . However, subsequent attempts to access a file through this file identifier variable will not work.
|
Writing Formatted Text Files | Exchanging Files over the Internet |
© 1994-2005 The MathWorks, Inc.