-
Notifications
You must be signed in to change notification settings - Fork 12
/
intervalToBinTimetable.m
42 lines (34 loc) · 1.27 KB
/
intervalToBinTimetable.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
33
34
35
36
37
38
39
40
41
42
function T = intervalToBinTimetable(Start,End,p)
% intervalToBinTimetable.m
% Simple script to get bin times of specified time from given intervals
Startnum = datenum(Start);
timevec = datevec(Startnum);
binStartEffort = datetime([timevec(:,1:4), floor(timevec(:,5)/p.binDur)*p.binDur, ...
zeros(length(timevec),1)]);
Endnum = datenum(End);
timevec = datevec(Endnum);
binEndEffort = datetime([timevec(:,1:4), floor(timevec(:,5)/p.binDur)*p.binDur, ...
zeros(length(timevec),1)]);
tbin = [];
effortBin = [];
effortSec = [];
for i = 1: length(Start)
currInterval = (binStartEffort(i):minutes(5):binEndEffort(i))';
if ~isempty(currInterval)
bin = ones(length(currInterval),1);
sec = ones(length(currInterval),1)*p.binDur*60;
% check if first and last bin are complete
if (binStartEffort(i)-Start(i)) ~= 0
bin(1) = (minutes(5)-(Start(i)-binStartEffort(i)))/minutes(5);
sec(1) = seconds(minutes(5)-(Start(i)-binStartEffort(i)));
end
if End(i) > binEndEffort(i)
bin(end) = (End(i) - binEndEffort(i))/minutes(5);
sec(end) = seconds(End(i) - binEndEffort(i));
end
tbin = [tbin;currInterval];
effortBin = [effortBin;bin];
effortSec = [effortSec;sec];
end
end
T = timetable(tbin,effortBin,effortSec);