How do I Append a Time Stamp?

2 views (last 30 days)
Matt Brown
Matt Brown on 13 Feb 2017
Answered: Walter Roberson on 13 Feb 2017
I have a spreadsheet containing a data file that has a time saved with hh:mm:ss in one columun then milliseconds in a second column. Can anyone clue me in on how to combine these to give a time stamp that shows hh:mm:ss:fff after I have read it into Matlab?

Answers (1)

Walter Roberson
Walter Roberson on 13 Feb 2017
[~, ~, raw] = xlsread('YourFile.xlsx');
tcol = raw(3:end, 1); %pull out appropriate column
mscol = raw(3:end, 2); %pull out appropriate column
assert(ischar(tcol{1}), 'Expected the time column to be character format');
if ischar(mscol{2}))
mscol = num2cell( str2double(mscol) );
end
mscol_num = cell2mat(mscol);
mscol_char_cell = cellstr( num2str( mscol_num, ':%03d') );
combined = strcat( tcol, mscol_char_cell );

Community Treasure Hunt

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

Start Hunting!