Create a time array
120 views (last 30 days)
Show older comments
Miguel Albuquerque on 30 Jun 2022
Answered: Steven Lord on 30 Jun 2022
Hey guys, thanks in advance.
I have one matrix of data( this is a char data) that has two times : as visible in this figure
those numbers are: hour-minutes-seconds-miliseconds
I need to produce a time array with duration in seconds between first element of this matrix and the last element(17-11-09_923).
I wanted to conserve the miliseconds, is there anyway?
Steven Lord on 30 Jun 2022
val = string(val);
Convert the string array val into a format the duration function knows how to import.
val = replace(val, '-', ':');
val = replace(val, '_', '.');
d = duration(val)
The fractional seconds are present, they're just not displayed with the default display Format. We can change the Format to show them.
d.Format = 'hh:mm:ss.SSS'
Now compute the difference in seconds.
More Answers (2)
Fangjun Jiang on 30 Jun 2022
Edited: Fangjun Jiang on 30 Jun 2022
Voss on 30 Jun 2022
val = [ ...
dt = datetime(val,'InputFormat','HH-mm-ss_SSS')
dt_diff = dt(end)-dt(1)
% the milliseconds are present in dt_diff:
Find more on Data Type Conversion 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!