conversion of [h,m,s] to h:m:s

1 view (last 30 days)
curious_koala
curious_koala on 15 Jun 2015
Edited: Stephen23 on 15 Jun 2015
How can I depict the time as a ax1 matrix in the form h:m:s instead of a ax3 matrix showing hour, minute and second in different columns?

Accepted Answer

Stephen23
Stephen23 on 15 Jun 2015
Edited: Stephen23 on 15 Jun 2015
You can easily convert the numeric array to a character array using sprintf:
>> A = [12,34,15;16,02,59];
>> B = reshape(sprintf('%02d:%02d:%02d',A'),[],size(A,1))'
B =
12:34:15
16:02:59
And simply wrap this in a cellstr to get these as strings in a cell array:
>> cellstr(B)
ans =
'12:34:15'
'16:02:59'

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!