Converting time to usable format

After calling a data source (CSV or xlsx) I need to be able to utilize the time column which was currently depicted utilizing the following format: 319:17:19:21.28 (Day, Hrs, Min, Sec, mS). How can I convert this to a usable time stamp?

2 个评论

By time stamp, a time vector containing time values in specific units: 319:17:19:21.28 converted to 319*24*60*60 + 17*60*60 + 19*60 + 21 + 28/1000 seconds
It does not mater to me the format in which the time stamps are displayed in my results. I simply want to call the "load" function to load my data file and gather my data. The first column I have is my time data which happens to be in the 319:17:19:21.28 format. When MatLab brings this column in, it cuts off the :17:19:21.28 values due to the semicolons thus only saving the 319 as the time value for that column. I would like to have the entire time stamp, not just the first portion.
How can I do this?

请先登录,再进行评论。

回答(1 个)

Is this what you are looking for?
>> datetime('319:17:19:21.28','InputFormat','DDD:HH:mm:ss.SS','Format','dd-MMM-yyyy HH:mm:ss.SSS')
ans =
datetime
15-Nov-2018 17:19:21.280
There's no year in your timestamp, so datetime assume "this year". Or maybe you want an elapsed time, not a datetime. Beginning in R2018a, you can do this:
>> duration('319:17:19:21.28','Format','dd:hh:mm:ss.SS')
ans =
duration
319:17:19:21.28
The load function loads a mat file, so I'm not following how anything could be cut off. You're going to have to say more about how you are importing the data. For a CSV of XLS[X], best bet is likely readtable.

类别

帮助中心File Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by