Read timestamp from data file with mixed formats
Ältere Kommentare anzeigen
I have a file with mixed date:
23.4 F15 2014-106T19:11:46
22.1 F16 2015-203T00:25:26
13.3 F100 2015-250T20:16:50
.
.
I know how to read the first two columns but I can't figure out how to scan the date and time from the third column. I tried:
formatSpec = '%f%s %{yyyy-DDDTHH:mm:ss}D';
delimiter = {'\t',' '};
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter,...
'MultipleDelimsAsOne', true, 'ReturnOnError', false);
but I get the error 'Badly formed format string'
Does anyone know what format can be used for the third column? Thanks.
3 Kommentare
per isakson
am 20 Apr. 2015
Bearbeitet: per isakson
am 20 Apr. 2015
Your |formatSpec | looks okay to me. Which Matlab release do you use? R2014b needed.
Orion
am 21 Apr. 2015
dpb
am 21 Apr. 2015
The issue is as noted in the Answer previously posted that you didn't enclose the non-recognized ASCII character inside the date format string in single quotes to escape it from the rest of the format string.
Akzeptierte Antwort
Weitere Antworten (1)
Peter Perkins
am 22 Apr. 2015
0 Stimmen
Hadi, in R2014b, you have the right format string for %D. But as Per points out, you need R2014b to use %D. In R2014a, you can read them as strings. But you have day-of-year in the strings, and the older datenum/datestr/datevec functions don't support that, so I think you're going to have to parse the separate pieces as numbers, and then put them together using datevec.
1 Kommentar
dpb
am 22 Apr. 2015
Version issue aside, the doc gives an example using an embedded 'T' in the %D string and specifically notes it (the T or any other non-specific date character must be a single-quoted string???? (The point being the string as Hadi initially posted isn't formatted properly as I read the doc, anyway, or by the example)
Kategorien
Mehr zu Data Type Conversion finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!