datenum seconds within minutes
이전 댓글 표시
Hello Every One, I have a question regarding datenum behavior (sorry if it has already asked, I haven't found it). I do not understand what is happening in the following cases because I was naively expecting the same value every time ?
>> datenum('00:00:00,998','hh:mm:ss,FFF')-datenum('00:00:00,997','hh:mm:ss,FFF')
ans =
1.164153218269348e-08
>> datenum('00:00:00,999','hh:mm:ss,FFF')-datenum('00:00:00,998','hh:mm:ss,FFF')
ans =
1.152511686086655e-08
>> datenum('00:00:01,000','hh:mm:ss,FFF')-datenum('00:00:00,999','hh:mm:ss,FFF')
ans =
1.164153218269348e-08
>> datenum('00:01:00,000','hh:mm:ss,FFF')-datenum('00:00:59,999','hh:mm:ss,FFF')
ans =
30.999305567122065
Thanks a lot for your help. E.
댓글 수: 1
채택된 답변
추가 답변 (1개)
Walter Roberson
2018년 3월 22일
0 개 추천
For datetime, mm is months, not minutes. You should be using HH:MM:SS,FFF
Anyhow, remember that datenum represents time as full days and fractions of a day, so you are seeing differences in the round-off of the last bit of a floating point number .
댓글 수: 1
Peter Perkins
2018년 3월 23일
Walter's point about day fractions is worth heeding. Multiples of 1/86400000 are inherently not representable exact in floating point. datetime (or maybe duration for your example?) will give you better answers (although the way I've shown it, you do have to mess with the display format):
>> duration(0,0,0,998) - duration(0,0,0,997)
ans =
duration
00:00:00
>> ans.Format = 'hh:mm:ss.SSS'
ans =
duration
00:00:00.001
카테고리
도움말 센터 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!