Textscan issue with txt file data delimited space : or .
1 view (last 30 days)
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.
Cam Salzberger on 5 Sep 2017
%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).