How to read a text file having strings and numeric data?
Show older comments
I have a 'txt' file with strings and numbers like this:
PATH VARIABLE SUMMARY
S UY EPTOX EPTOZ
0.0000 -0.53581E-01 0.10604E-03-0.32000E-04
1.0000 -0.54013E-01 0.10653E-03-0.32322E-04
2.0000 -0.54450E-01 0.10702E-03-0.32638E-04
3.0000 -0.54893E-01 0.10747E-03-0.32752E-04
etc...
PATH VARIABLE SUMMARY
S UY EPTOX EPTOZ
42.000 -0.76168E-01 0.12966E-03-0.22470E-04
43.000 -0.76806E-01 0.13042E-03-0.21690E-04
44.000 -0.77447E-01 0.13119E-03-0.20854E-04
etc...
I need to read only numeric data as an array. I don't foreknow number of string lines in file and their format (!). I tried 'dlmread', but it terminates with an error.
In Mathcad, for example, I use 'READPRN', which ignores any text and reads numeric data from file without any problems. So now I have to read my files in Mathcad, export them to EXCEL and then read in MATLAB with 'xlsread'.
4 Comments
jonas
on 6 Aug 2018
Try readtable
Denis Perotto
on 6 Aug 2018
Stephen23
on 6 Aug 2018
@Denis Perotto: does the file always have four columns of numeric data? Or can the number of columns change?
Denis Perotto
on 6 Aug 2018
Accepted Answer
More Answers (0)
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!