How to read non-rectangular text file?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Bob Thompson
2018년 3월 28일
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.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!