I have a question regarding to read a txt file in matlab were the format is not know , but each row in the txt file always start like this:
2012-11-01 00:00:00.00 XX YY 00.000s
Then some different stuff is logged and the txt file can look different, for example
Ex1: 2012-11-01 00:00:00.00 XX YY 00.000s 000.00deg 0.00rpm 0.00rpm
Ex2: 2012-11-01 00:00:00.00 XX YY 00.000s 000.00deg 0.00rpm
Ex3: 2012-11-01 00:00:00.00 XX YY 00.000s 0.00deg 0.00rpm 0.00rpm 0.0deg
Ex4: 2012-11-01 00:00:00.00 XX YY 00.000s 0.00rpm
I handle this with textscan
and use:
Fid = fopen('text.txt');
initfrm = {'%s%s%s%s %.3f %s'};
frm = repmat('%.2f %s',1,NCol);
frm = strcat(initfrm, frm);
Tmp = textscan(fid,frm{1});
Fclose(fid);
In the file its calculated how many col (NCol
) we have logged but is not showed here
But sometimes the text file includes 0.0%
, for example:
Ex1: 2012-11-01 00:00:00.00 XX YY 00.000s 000.00deg 0.00rpm 0.00rpm 0.0%
Now '%.2f'
won’t work. I don’t know when the log is like this. Is there a better way to separate the float and string when they are printed together; I just want collect the data (float) so I can plot.
How can I get all float values when it varies with %.2f and %.1f; you don't know the pattern.