Read a text file with varying number of colums
显示 更早的评论
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 个评论
dpb
2015-1-11
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
2015-1-12
What's the role of "," ?
Pankaj
2015-1-12
Pankaj
2015-1-12
采纳的回答
更多回答(1 个)
Aditya Dua
2015-1-11
0 个投票
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
类别
在 帮助中心 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!