How can I read text file with number of elements in each line is different?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Walter Roberson
il 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Text Files in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!