Read timestamp from data file with mixed formats
Mostrar comentarios más antiguos
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 comentarios
per isakson
el 20 de Abr. de 2015
Editada: per isakson
el 20 de Abr. de 2015
Your |formatSpec | looks okay to me. Which Matlab release do you use? R2014b needed.
Orion
el 21 de Abr. de 2015
dpb
el 21 de Abr. de 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.
Respuesta aceptada
Más respuestas (1)
Peter Perkins
el 22 de Abr. de 2015
0 votos
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 comentario
dpb
el 22 de Abr. de 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)
Categorías
Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!