Converting Given times to a Vector
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
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.
0 个评论
回答(2 个)
Star Strider
2016-3-25
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 个评论
marco hosfeld
2016-3-25
Star Strider
2016-3-25
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
2016-3-25
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.
0 个评论
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!