MATLAB Answers

per isakson

fgetl, textscan, and the file position indicator

Asked by per isakson
on 7 Sep 2012

Is a construct like this legal?

It doen't return any error, but the "file position indicator" is not advanced as it should. I read a text file CRLF for new line.

    fid = fopen( ... );
    str = fgetl( fid );
    cac = textscan( fid, ... );
    str = fgetl( fid );
    cac = textscan( fid, ... );
    fclose( fid ) 



No products are associated with this question.

1 Answer

Answer by Walter Roberson
on 7 Sep 2012
Edited by Walter Roberson
on 7 Sep 2012
 Accepted answer

That series is valid, yes.

Did you open the file with 'rt' instead of 'r' in order to account for the CRLF ?

Also note that if you use a count for textscan() then the file position will be left after the last format code is used, before the newline for that line (unless the end of format matches newline)


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!