フィルターのクリア

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 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