This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Read line from file, removing newline characters


tline = fgetl(fileID)


tline = fgetl(fileID) returns the next line of the specified file, removing the newline characters. fileID is an integer file identifier obtained from fopen. tline is a character vector unless the line contains only the end-of-file marker. In this case, tline is the numeric value -1.

fgetl reads characters using the encoding scheme associated with the file. To specify the encoding scheme, use fopen.


Read and display the file fgetl.m one line at a time:

fid = fopen('fgetl.m');

tline = fgetl(fid);
while ischar(tline)
    tline = fgetl(fid);


Compare these results to the fgets example, which replaces the calls to fgetl with fgets.

Introduced before R2006a

Was this topic helpful?