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

조회 수: 26 (최근 30일)
Ashley
Ashley 2013년 6월 23일
답변: Peter Perkins 2016년 1월 14일
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

답변 (2개)

Peter Perkins
Peter Perkins 2016년 1월 14일
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 2013년 6월 23일
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
Jan
Jan 2013년 6월 24일
It depends on what you want to do with the values. Please explain more details.
PTP
PTP 2016년 1월 13일
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.

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

카테고리

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