Converting hhmmss.mmm to hh:mm:ss.mmm, or something like that
4 views (last 30 days)
Show older comments
My array includes a column of time data which is in the format "hhmmss.mmm".
An example is "155313.894", which means 15:53:13.894 (hh:mm:ss.mmm).
I would like to convert this value into a time value that I can use to plot in either Matlab or Excel.
datestr($$$) does not work because there is no date data, only time.
Suggestions? Help?
Thanks!
-adam-
0 Comments
Answers (2)
Jan
on 17 May 2011
Str = '155313.894';
Converted1 = sprintf('%c%c:%c%c:%s', Str)
Or:
Converted2 = [Str(1:2), ':', Str(3:4), ':', Str(5:10)]
2 Comments
Jan
on 18 May 2011
What kind of array do you use? For a cell array:
for a = 1:length(array); array{a} = sprintf('%0.3f', array{a}); end
The original question for a CHAR array:
Converted = strcat(Str(:, 1:2), ':', Str(:, 3:4), ':', Str(:, 5:10)];
Matt Fig
on 17 May 2011
It is not clear to me whether you want a number or another string in a different format. If you want a number, stop after the first line below:
N = datenum('155313.894','HHMMSS.FFF')
S = datestr(N,13) % Pick which format you like. See DATESTR help.
0 Comments
See Also
Categories
Find more on Language Support 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!