How can I read text file with number of elements in each line is different?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Walter Roberson
le 30 Avr 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Text Files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!