datetime - Matlab: Add Milliseconds to time vector hh:mm:ss -


i have matrix

m =  hh:mm:ss ms '12:00:01' 1 '12:00:02' 2 '12:00:03' 3 '12:00:04' 4 '12:00:05' 5 

now want add array of milliseconds ms time vector. like

   n =      hh:mm:ss     '12:00:01.001'     '12:00:02.002'     '12:00:03.003'     '12:00:04.004'     '12:00:05.005' 

how can this? tried was:

for k=1:length(m)     t1 = datenum(m{k,1},'hh:mm:ss');     c = num2str(m{k,2});     t2 = datenum(c,'fff');     time = t1+t2;     n{k,1} = datestr(time,'hh:mm:ss.fff'); end 

but did not job right. is:

n =  hh:mm:ss '12:00:01.100' '12:00:02.200' '12:00:03.300' ... '12:00:04.100' '12:00:05.110' '12:00:05.120' 

i think problem simple solve. @ moment not know how solve it.

it's string formatting problem.

in code, instead of

c = num2str(m{k,2}); 

use

c = sprintf('%03d',m{k,2}); 

in above usage, sprintf pads zeros in front of string if it's less 3 characters long.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -