How to read non-rectangular text file?

3 views (last 30 days)
Hi All,
I'm having trouble on figuring out how to read this file... It's a text file with an odd format (see below), and I wish to have all numerical values in a matrix. I've tried textscan/textread/fscanf etc.. Any suggestions on how to read this? Any help is much much appreciated!!
1 170.411 17.701 171.50 0.635 0.808 1000.0 1.000 1.00 0 1 3 2 ( 35.7) 17 ( 22.8) 25 ( 19.8)
2 331.737 7.687 36.14 3.721 0.780 1000.0 1.000 1.00 0 1 7 1 ( 35.7) 3 ( 19.1) 17 ( 14.9) 19 ( 12.0) 21 ( 12.2) 26 ( 19.9) 28 ( 16.9)
3 307.133 16.214 43.80 6.711 0.701 1000.0 1.000 1.00 0 1 6 2 ( 19.1) 4 ( 27.5) 16 ( 28.1) 19 ( 11.7) 21 ( 25.3) 22 ( 20.3)
4 103.491 10.151 257.58 9.413 0.022 1000.0 1.000 1.00 0 1 3 3 ( 27.5) 16 ( 18.5) 5 ( 16.4)
Thanks all!
Ben
  2 Comments
Bob Thompson
Bob Thompson on 28 Mar 2018
My sloppy form would be to write a while loop which will read each line with fgetl(). It will require some finessing since fgetl classes the line as a string, but you can convert the string values into a set of numbers afterwards and pad a matrix.
Benjamin Schuessler
Benjamin Schuessler on 28 Mar 2018
I figured it out! Just find and replace the () in notepad... works good enough for me.

Sign in to comment.

Answers (0)

Categories

Find more on Characters and Strings 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!