Date with microseconds in MATLAB
I have a table with a lot of dates like this: 17: 01: 11.356078. I know the data doesn't have microsecond processing precision. Also datevec is not good for this, infact the date became 3.5608e + 5 (milliseconds) using it. I need microsecond precision because I have to calculate delta times.
source to share
If you have the option to use the latest R2014b, it includes a revision of date and time handling, including new objects datetime
that handle nanosecond precision.
Prior to that, you're a bit stuck if you need more than a millisecond accuracy, and you may need to implement your own way to store and manage your time, rather than relying on the built-in datenum
and datestr
etc.
source to share
Existing date formats in matlab don't allow anything less than microseconds. Therefore, the solution is to avoid these formats.
A relatively easy way to do this is to divide the numbers. For example, there is 1 vector with dates rounded to the second and another vector with fractions of a second. This way you can get very high accuracy when needed.
Computing the difference would be done by adding the difference in seconds to the difference elsewhere. (Using a constant to scale the difference)
source to share
the problem with the date is that you are limited to double precision. If you get rid of the day bias by supplying a date string 0-jan-0000-hrs:mins:secs
, the data is perfectly capable of resolving redemptive seconds. This is only useful if you are not interested in dates, but again it will be a problem, however you are converting to double
source to share