MATLAB: Conversion of [h,m,s] to h:m:s

matixtime

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?

Best Answer

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'
Related Question