필터 지우기
필터 지우기

what is the precision of a MATLAB datenum?

조회 수: 21 (최근 30일)
Tony
Tony 2012년 8월 10일
답변: Peter Perkins 2015년 7월 27일
I'm trying to timestamp samples at a 20MHz (50 ns period) using datenum, and subsequent timestamps all come out the same when I examine them with datevec (seconds column). Is this just a display issue or am I running up against the precision of datenum?

채택된 답변

Jonathan Sullivan
Jonathan Sullivan 2012년 8월 10일
Well, let's find out.
Let's take a look at the precision of the time "now," converted to seconds
reference = now;
precision = eps(reference);
precision_seconds = precision*24*3600
Looks like about 10 us for an absolute timestamp.
If you want a relative timestamp with a max value of 1 day, we get the following:
reference = 1;
precision = eps(reference);
precision_seconds = precision*24*3600
Now we get a precision of about 0.02 ns.

추가 답변 (2개)

Peter Perkins
Peter Perkins 2015년 7월 27일
As Ian says, the precision of datenums for contemporary dates is about 10 microseconds:
>> eps(now)*86400
ans =
1.0058e-05
Since R2014b, you can use the new datetime data type, which has much higher precision than datenum. For example:
>> d0 = datetime(2015,7,27,12,0,0,'Format','dd-MMM-yyyy HH:mm:ss.SSSSSSSSS')
d0 =
27-Jul-2015 12:00:00.000000000
>> d1 = d0 + seconds([1e-3 1e-6 1e-9])
d1 =
27-Jul-2015 12:00:00.001000000 27-Jul-2015 12:00:00.000001000 27-Jul-2015 12:00:00.000000001
>> seconds(d1 - d0)
ans =
0.001 1e-06 1e-09

the cyclist
the cyclist 2012년 8월 10일
편집: the cyclist 2012년 8월 10일
The documentation of the datevec() function suggests to me that the precision is 1 millisecond.
A bit of playing around gives that this
>> datenum('01-00-0000 00:00:00.0001')
has a non-zero value, but this
>> datenum('01-00-0000 00:00:00.00001')
is zero, suggesting that maybe it is down around the 100 microseconds, but not 10 microseconds.
  댓글 수: 1
Ian
Ian 2015년 7월 27일
The precision of cyclist's answer is driven by the code converting the date string, not the precision of datenums. Datenums are currently of type double in matlab, with about 15 decimal digits of precision. We're about 736000 days past year 0, so that leaves a precision of about 1e-10 days, or ballpark 10 usecs (as correctly implied by JSullivan's answer):
>> d1=datenum(now);
>> d2=[d1+1e-10, d1+5e-11];
>> d2==d1
ans =
0 1

댓글을 달려면 로그인하십시오.

카테고리

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