Textscan issue with txt file data delimited space : or .
1 回表示 (過去 30 日間)
古いコメントを表示
Hello I am using textscan to export data from txt file:
'17:12:35 -1 -1 1 12 -1 -10.017 35 comment'
I would like to separate in each data value (hours min sec # # # # # #.# # string)
I used data = [textscan(fopen(strcat(PathName, FileName)),'%f:%f:%f %f %f %f %f %f %f.%f %f %s','Delimiter','\t','HeaderLines', 17)];
It works fine to distinguish time in hours min and sec, however I don't know how to delimit when the dot occurs. I have 2 different value informations. One before and one after the dot that I need to separate.
Any help?
Thank you
0 件のコメント
回答 (1 件)
Cam Salzberger
2017 年 9 月 5 日
Hello Mafalda,
%f will specify to interpret the text as a floating point number. Since floating point numbers can have decimals, it accepts the period as part of the number.
I can think of two options here:
1) Assuming you'll never have an entry like "3.1414.27", you can try accepting both the numbers around the period as integers (%d or %i) instead of floating point. Then convert back to double afterwards.
2) Accept it as a single double, and split it into two entities afterwards (using mod and round or something along those lines).
-Cam
2 件のコメント
Cam Salzberger
2017 年 9 月 5 日
Hmm, when I do a simple parse, it seems to work for the integer datatypes.
teststr = '17:12:35 -1 -1 1 12 -1 -10.017 35 comment';
sscanf(teststr,'%f:%f:%f\t%f\t%f\t%f\t%f\t%f\t%d.%d\t%f\t%s')
Maybe it's something specific about textscan's arguments? Glad the second option is working for you though.
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!