Converting Time Intervals into seconds

Hi! I am having issues converting a time interval (difference between 2 timestamps) into seconds.
I set instrument at 5 second intervals, but the instrument randomly missed 10-30 seconds of data.
'13:59:30'
'13:59:35'
'13:59:40'
'13:59:45'
'13:59:50'
'13:59:55'
'14:00:30'
'14:00:35'
'14:00:40'
'14:00:45'
'14:00:50'
I'm now trying to integrate my data over the time of our test Conc (i) in M/L^3 * flow rate (L^3/s) * dt (S) to get M.
However, I can't get the difference (for example) of 14:00:00 and 14:00:05 to just be 5.
I have tried second, datenum, datevec, and other functions to no avail. I seem to only get answers as 00:00:05, which causes my final answer to be xx:xx:xx, or when I use datenum(dt), I get a really small number (E-5).
Any help would be much appreciated!
thank you!

Answers (1)

dpb
dpb on 4 Oct 2016
Edited: dpb on 4 Oct 2016
I don't have recent release so can't use datetime class, but datenum returns time in days and fractions thereof. Simply convert to seconds by the number of seconds/day...
>> dn=datenum(ts,'HH:MM:SS'); % ts is your sample timestamps
>> dt=diff(dn)*86400
dt =
5.0000
5.0000
5.0000
5.0000
5.0000
35.0000
5.0000
5.0000
5.0000
5.0000
>>
Or, of you want the time vector, simply subract the initial value...
>> t=(dn-dn(1))*86400
t =
0
5.0000
10.0000
15.0000
20.0000
25.0000
60.0000
65.0000
70.0000
75.0000
80.0000
>>

2 Comments

Both seemed to work; thank you!
Glad to help.
"ACCEPT" the answer to show issue resolved, then, if you would...

Sign in to comment.

Categories

Asked:

on 4 Oct 2016

Commented:

dpb
on 4 Oct 2016

Community Treasure Hunt

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

Start Hunting!