How can I read text file with number of elements in each line is different?

1 次查看(过去 30 天)
I have an input text file:
result.txt:
0
[0
0
0
3,19,24,44,47
0.17221,0.26928,0.1476,0.2485,0.16241]
I used load function in matlab to read it (load('result.txt')), but I couldn't. How do I read this file?
Thank for your help!

采纳的回答

Walter Roberson
Walter Roberson 2016-4-30
None of the standard data importing routines can handle that file because of the '[' and ']'. You could use textscan for part of it, but it probably is not worthwhile doing so. It would be easier to use fgetl() and sscanf(), or to use fileread() and regexp() .
You have not defined the desired output variables. MATLAB numeric arrays cannot have different numbers of elements per row, so if you want to preserve the structure you will need to use multiple variables or you will need to use cell arrays,
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by