MATLAB Function Reference | Search  Help Desk |
fopen | See Also |
Open a file or obtain information about open files
fid = fopen(Iffilename
,permission
) [fid,message] = fopen(filename
,permission
,format
) fids = fopen('all') [filename,permission, format] = fopen(fid)
fopen
successfully opens a file, it returns a file identifier fid
, and the value of message
is empty. The file identifier can be used as the first argument to other file input/output routines. If fopen
does not successfully open the file, it returns a -1
value for fid
. In that case, the value of message
is a string that helps you determine the type of error that occurred.
Two fid
s are predefined and cannot be explicitly opened or closed:
permission
set to 'a'
), and
permission
set to 'a'
).
fid = fopen(filename
,permission
)
opens the file filename
in the mode specified by permission
and returns fid
, the file identifier. filename
may a MATLABPATH
relative partial pathname. If the file is opened for reading and it is not found in the current working directory, fopen
searches down MATLAB's search path.
permission
is one of the strings:'t'
to these strings, for example, '
rt
'
, on systems that distinguish between text and binary files, to force the file to be opened in text mode. Under DOS and VMS, for example, you cannot read a text file unless you set the permission to 'rt'
. Similarly, use a 'b'
to force the file to be opened in binary mode (the default).
[fid,message] = fopen(filename
,permission
,format
)
opens a file as above, returning file identifier and message. In addition, you specify the numeric format with format
, a string defining the numeric format of the file, allowing you to share files between machines of different formats. If you omit the format
argument, the numeric format of the local machine is used. Individual calls to fread
or fwrite
can override the numeric format specified in a call to fopen
. Permitted format strings are:fids = fopen('all')
returns a row vector containing the file identifiers of all open files, not including 1 and 2 (standard output andstandard error). The number of elements in the vector is equal to the number of open files.
[filename,permission,format] = fopen(fid)
returns the full filename
string, the permission
string, and the format
string associated with the specified file. An invalid fid
returns empty strings for all output arguments. Both permission
and format
are optional.
fclose
Close one or more open files
ferror
Query MATLAB about errors in file input or output
fprintf
Write formatted data to file
fread
Read binary data from file
fscanf
Read formatted data from file
fseek
Set file position indicator
ftell
Get file position indicator
fwrite
Write binary data from a MATLAB matrix to a file
See also partialpath.