Effacer les filtres
Effacer les filtres

what is the precision of a MATLAB datenum?

21 vues (au cours des 30 derniers jours)
Tony
Tony le 10 Août 2012
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?

Réponse acceptée

Jonathan Sullivan
Jonathan Sullivan le 10 Août 2012
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.

Plus de réponses (2)

Peter Perkins
Peter Perkins le 27 Juil 2015
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 le 10 Août 2012
Modifié(e) : the cyclist le 10 Août 2012
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 commentaire
Ian
Ian le 27 Juil 2015
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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by