Open file, or obtain information about open files
fileID = fopen(
opens
the file, filename
)filename
, for binary read access, and
returns an integer file identifier equal to or greater than 3. MATLAB® reserves
file identifiers 0
, 1
, and 2
for
standard input, standard output (the screen), and standard error,
respectively.
If fopen
cannot open the file, then fileID
is -1
.
fileID = fopen(
opens
the file with the type of access specified by filename
,permission
)permission
.
fileID = fopen(
additionally
specifies the order for reading or writing bytes or bits in the file
using the filename
,permission
,machinefmt
,encodingIn
)machinefmt
argument. The optional encodingIn
argument
specifies the character encoding scheme associated with the file.
[fileID,errmsg] = fopen(___)
additionally
returns a system-dependent error message if fopen
fails
to open the file. Otherwise, errmsg
is an empty
character vector. You can use this syntax with any of the input arguments
of the previous syntaxes.
fIDs = fopen('all')
returns a row vector
containing the file identifiers of all open files. The identifiers
reserved for standard input, output, and error are not included. The
number of elements in the vector is equal to the number of open files.
filename = fopen(
returns
the file name that a previous call to fileID
)fopen
used
when it opened the file specified by fileID
. The
output filename is resolved to the full path. The fopen
function
does not read information from the file to determine the output value.
[filename,permission,machinefmt,encodingOut] = fopen(
additionally
returns the permission, machine format, and encoding that a previous
call to fileID
)fopen
used when it opened the specified
file. If the file was opened in binary mode, permission
includes
the letter 'b'
. The encodingOut
output
is a standard encoding scheme name. fopen
does
not read information from the file to determine these output values.
An invalid fileID
returns empty character vectors
for all output arguments.
In most cases, it is not necessary to open a file
in text mode. MATLAB import functions, all UNIX applications,
and Microsoft Word and WordPad recognize '\n'
as
a newline indicator.