Programming Previous page   Next Page

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.


Previous page  Writing Formatted Text Files Exchanging Files over the Internet Next page

© 1994-2005 The MathWorks, Inc.