How can I read text file with number of elements in each line is different?
    4 views (last 30 days)
  
       Show older comments
    
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!
0 Comments
Accepted Answer
  Walter Roberson
      
      
 on 30 Apr 2016
        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 Comments
More Answers (0)
See Also
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!
