How to remove/skip text at beginning of a file while reading it using textscan?

4 views (last 30 days)
I obtain a file (data.dat) from the tests looking something like:
" # Fix print output for fix output_fix
2.08961637595025 0 0 -0.0999999999999419 4.16318208254011e-08 8.4252204541061e-08 0.0816630066803504 -0.0816630066803506 -3.97606504059701e-10 -8.04654348855725e-10 -2.50587947838166 200 0 -2.5 300 0 -2.5 400 0 -2.5
4.1792327519005 0 0 -0.0999999999999419 -1.26671703863963e-05 -2.02452275457547e-05 0.50566955186541 ...."
Each value after the text represents a data which I group into 20 cells of matrix by using textscan using the code:
fid=fopen(data.dat);
S=textscan(fid,'%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f');
How can I avoid the "# Fix print output for fix output_fix"at the beginning while using textscan?
I don't want to manually delete the text at each file. Please help. Thanks

Accepted Answer

Star Strider
Star Strider on 14 Aug 2018
If the text line is a separate line at the beginning of the file (as it appears to be), use the HeaderLines (link) name-value pair to specify the number of header lines to skip.
  4 Comments
Tanmaya Mishra
Tanmaya Mishra on 14 Aug 2018
Thanks a lot.
Specify Text to be Treated as Empty or Comments (link) (using the 'CommentStyle' (link) name-value pair) works.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!