Converting Given times to a Vector
Info
This question is closed. Reopen it to edit or answer.
Show older comments
I have a series of 4158 time points that i must convert from the hh:mm:ss.ss format to something i can use in matlab. this set of data is contained in cells in excel.
Answers (2)
Star Strider
on 25 Mar 2016
Without having your file it’s difficult to write specific code. However:
time_cell = {'12:34:56.01'; '12:34:57.50'}; % Create Data
dn = datenum(time_cell, 'HH:MM:SS.FFF'); % Convert To Date Numbers
Check = datevec(dn) % Check Conversion (Delete)
will work if I made the correct assumptions about it.
2 Comments
marco hosfeld
on 25 Mar 2016
Star Strider
on 25 Mar 2016
My pleasure.
You said your times were a cell array of strings, that is likely correct if you used the xlsread function to import your data. They don’t have to look exactly the same as the cell array I used to test my code.
Did you test your data with my code example?
Did it work?
If not, what was the error?
Steven Lord
on 25 Mar 2016
Rather than using serial date numbers as Star Strider suggested, if you're using a release where it is available (release R2014b or later) I recommend using datetime with the 'InputFormat' option to specify the format of the dates in the cellstr.
time_cell = {'12:34:56.01'; '12:34:57.50'};
timeFormat = 'hh:mm:ss.SS';
dateVector = datetime(time_cell, 'InputFormat', timeFormat);
dateVector.Format = timeFormat
The last line changes the format used to display the date vector to match the format as it was imported so that the display of the dateVector should match exactly what you see in time_cell.
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!