Using datevec with hh.mm.ss.ss gives error [R2017b]

2 visualizaciones (últimos 30 días)
TJ
TJ el 20 de Dic. de 2017
Comentada: TJ el 20 de Dic. de 2017
Good afternoon,
I have found some similar questions but none that ask this specific case and I have tried just about every possible solution I can think of, but very much need to use datevec and retain the decimal seconds portion of the seconds. I have a data acquisition file with a very high sample rate (96000 samples per second). The time stamp is in the format hh:mm:ss.ss (note it is not hh:mm:ss.sss). I have tried the following formats with the datevec function and none are working:
datevec(data,'hh:mm:ss.ff')
datevec(data,'hh:mm:ss.ss')
datevec(data,'hh:mm:ss.SS')
Is this possible with datevec?
Cheers, TJ

Respuestas (1)

Jan
Jan el 20 de Dic. de 2017
According to the documentation doc datestr the format must be:
'HH:MM:SS.FFF'
The upper-case matters, because e.g. 'mm' is the month with 2 digits. There is no "ff" format specifier, but only "FFF".
If you post the inputs you have, suggesting and testing code would be easier. I using the correct format specifiers does not help, what about using a simple sscanf instead?
data = '23:17:54.21'
n = sscanf(data, '%d:%d:%f', [1, 3]);
vec = [zeros(1, 3), n];
  1 comentario
TJ
TJ el 20 de Dic. de 2017
Hi Jan,
Thanks for the answer. Does the .FFF necessarily mean three decimal places or is it just a format for having decimal seconds? I am just wondering how one would then adapt it for instances where you use different precisions such as s.s or s.ss.
The data is as you assumed above: '14:12:31.23'
I will try the sscanf method, thanks.

Iniciar sesión para comentar.

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by