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

3 ビュー (過去 30 日間)
TJ
TJ 2017 年 12 月 20 日
コメント済み: TJ 2017 年 12 月 20 日
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 日
What is "data"?

サインインしてコメントする。

回答 (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 Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by