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!