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

조회 수: 2 (최근 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일
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