Read a text file with varying number of colums
Afficher commentaires plus anciens
I am trying to read a text file with varying number of columns, such as this:
#5:v3.0_ST:1:2631.1301,N:140.0:081.000:12.5;
#5:v3.0_ST:1:2631.1301,N:111.4:100.000:12.5:18.7:32.3;
#5:v3.0_ST:1:2631.1299,N:111.5:101.000:12.5:18.7:32.3;
#5:v3.0_ST:1:2631.1315,N:136.4:082.000:12.3;
#5:v3.0_ST:1:2631.1334,N:132.8:083.000:12.4;
The data is delimited by " : " (colon). I understand, there is some way of doing this using textscan, but I do not know how to do it for varying columns. Can someone give me a hint?
Thanks
4 commentaires
dpb
le 11 Jan 2015
HINT:
doc fgetl
Your file has no clues in it for how many items there are per line other than counting delimiters on a line-by-line basis, unfortunately. Hence, that's the only way...
per isakson
le 12 Jan 2015
What's the role of "," ?
Pankaj
le 12 Jan 2015
Pankaj
le 12 Jan 2015
Réponse acceptée
Plus de réponses (1)
Aditya Dua
le 11 Jan 2015
0 votes
I tried this on the file segment you posted and it worked:
inp = importdata('file.txt'); where inp(k) contains the k^th line of the text file.
I'm using MATLAB R2014b
Aditya
Catégories
En savoir plus sur Graphics Object Properties dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!