| MATLAB Function Reference | ![]() |
Read line from file, keeping newline character
Syntax
Description
tline = fgets(fid)
returns the next line of the file associated with file identifier fid. If fgets encounters the end-of-file indicator, it returns -1. (See fopen for a complete description of fid.) fgets is intended for use with text files only.
The returned string tline includes the line terminators associated with the text line. To obtain the string without the line terminators, use fgetl.
tline = fgets(fid, nchar)
returns at most nchar characters of the next line. No additional characters are read after the line terminators or an end-of-file.
Remarks
When reading character strings from files, pass the output of fgets to the MATLAB native2unicode function to ensure that characters display correctly:
See Also
| fgetl | fieldnames | ![]() |
© 1994-2005 The MathWorks, Inc.