-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeElapsed.m
32 lines (28 loc) · 940 Bytes
/
timeElapsed.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function newArray = timeElapsed(datetime_array)
% This function converts an array of elements in datetime format
% into the total elapsed time in seconds since the first data point was
% acquired
%
% To find out more about datetime formats and arrays try the command:
%
% >> doc datetime
%
% Copyright 2018 The MathWorks, Inc
newArray = second(datetime_array);
arraySize = numel(newArray); %Number of elements in the array
first = newArray(1);
i = 1;
% The following loop will run until it reaches the end of the array.
% Whenever the next number is smaller than the current number the loop will
% add 60 seconds and then start at the begining of the array again.
while i < arraySize
if newArray(i) > newArray(i+1)
newArray(i+1) = newArray(i+1) +60;
i = 1;
end
i = i+1;
end
% Subtract the first number to all elements of the array in order to start
% the array at 0.
newArray = newArray - first;
end