time | calls | line |
---|
| | 1 | function tline = fgetl(fid)
|
| | 2 | %FGETL Read line from file, discard newline character.
|
| | 3 | % TLINE = FGETL(FID) returns the next line of a file associated with file
|
| | 4 | % identifier FID as a MATLAB string. The line terminator is NOT
|
| | 5 | % included. Use FGETS to get the next line with the line terminator
|
| | 6 | % INCLUDED. If just an end-of-file is encountered, -1 is returned.
|
| | 7 | %
|
| | 8 | % If an error occurs while reading from the file, FGETL returns an empty
|
| | 9 | % string. Use FERROR to determine the nature of the error.
|
| | 10 | %
|
| | 11 | % MATLAB reads characters using the encoding scheme associated with the
|
| | 12 | % file. See FOPEN for more information.
|
| | 13 | %
|
| | 14 | % FGETL is intended for use with files that contain newline characters.
|
| | 15 | % Given a file with no newline characters, FGETL may take a long time to
|
| | 16 | % execute.
|
| | 17 | %
|
| | 18 | % Example
|
| | 19 | % fid=fopen('fgetl.m');
|
| | 20 | % while 1
|
| | 21 | % tline = fgetl(fid);
|
| | 22 | % if ~ischar(tline), break, end
|
| | 23 | % disp(tline)
|
| | 24 | % end
|
| | 25 | % fclose(fid);
|
| | 26 | %
|
| | 27 | % See also FGETS, FOPEN, FERROR.
|
| | 28 |
|
| | 29 | % Copyright 1984-2011 The MathWorks, Inc.
|
| | 30 |
|
30.42 | 4716187 | 31 | narginchk(1,1)
|
| | 32 |
|
45.89 | 4716187 | 33 | [tline,lt] = fgets(fid);
|
26.17 | 4716187 | 34 | tline = tline(1:end-length(lt));
|
6.23 | 4716187 | 35 | if isempty(tline)
|
| | 36 | tline = '';
|
| | 37 | end
|
| | 38 |
|
12.93 | 4716187 | 39 | end
|