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

New to MATLAB?

fgetl, textscan, and the file position indicator

Asked by per isakson

per isakson (view profile)

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 ) 

0 Comments

per isakson

per isakson (view profile)

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson

Walter Roberson (view profile)

on 7 Sep 2012
Edited by Walter Roberson

Walter Roberson (view profile)

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)

0 Comments

Walter Roberson

Walter Roberson (view profile)

Contact us