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

1 次查看(过去 30 天)
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

回答(1 个)

Jan
Jan 2017-12-20
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 个评论
TJ
TJ 2017-12-20
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by