How to import date/time data into matlab with microsecond precision

92 views (last 30 days)
Hello,
I am quite new to Matlab, so am having difficulty with this issue. I am importing sensor data from a text file. The sensor used has a fast sampling rate, and so milliseconds is not enough precision for my purpose. I need precision of microseconds i.e. mm/dd/yy HH:MM:SS.######
I am using the "Import" GUI to import data, and I see no option to import the date/time information at microseconds percision.
Here is a print screen that will give you more of a feel for my scenario: http://img196.imageshack.us/img196/923/lbwt.png
In the print screen, I only want to import the data from column A; the date/time information that is in mm/dd/yy HH:MM:SS.xxxxxx format (where x is the microseconds), which represents the sample time for all the data in the other columns.
I am trying to import this information at mm/dd/yy HH:MM:SS.xxxxxx precision, but do not know how to, can anyone help?
Regards, Ashley

Answers (2)

Peter Perkins
Peter Perkins on 14 Jan 2016
I see things like '06/18/13 16:55:01.581688' in your file. From your screenshot, it looks like you're using a version of MATLAB prior to R2014b. There's no datestr format to support more than milliseconds, and in any case, microseconds are beyond the resolution for MATLAB serial date numbers. That was the point Jan was trying to make: To retain all the way down to microseconds, you'll have to import those timestamps as strings, and then split apart the strings and parse the pieces separately. You might then put them back together as serial date numbers, and if you don't actually care about retaining the full precision, you'd be fine. If you do care, you'll have to keep around the two pieces.
Higher precision is one of the reasons why datetime was introduced in R2014b.
In R2014b or later, you can convert that to a datetime very easily, using the import tool, or read them in as strings and convert afterwards. For example, at the command line:
>> datetime('06/18/13 16:55:01.581688','Format','MM/dd/yy HH:mm:ss.SSSSSS')
ans =
06/18/13 16:55:01.581688

Jan
Jan on 23 Jun 2013
You cannot import a time in string format with microseconds directly, because Matlab's serial date numbers can carry milliseconds precision only. When the date is considered also, trying to store microseconds exceeds the available precision of the type double, which is used for serial date numbers.
This means, that you have to create your own time format and the import needs an individual method.
  3 Comments
Jan
Jan on 24 Jun 2013
It depends on what you want to do with the values. Please explain more details.
PTP
PTP on 13 Jan 2016
Hey Jason, I am implementing PTP(IEEE 1588) protocol in Matlab and for that i need time to be in Microseconds. I know matlab can handle time in milliseconds precisely. Any ideas how i can do that, Because i need to measure cputime in microseconds. Your help would be highly appreciated.

Sign in to comment.

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!