-
Notifications
You must be signed in to change notification settings - Fork 1
/
extractStepSegments.m
37 lines (29 loc) · 1.14 KB
/
extractStepSegments.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
function [dataSeg] = extractStepSegments(data,mode,stepNum)
idxStepNum = mode == stepNum;
fldNames = fieldnames(data);
if idxStepNum(1) ~= 0 && idxStepNum(end) == 0
idxStepNum = [0; idxStepNum];
numStepNumOccStart = find(diff(idxStepNum) == 1);
numStepNumOccEnd = find(diff(idxStepNum) == -1);
elseif idxStepNum(end) ~= 0 && idxStepNum(1) == 0
idxStepNum = [idxStepNum; 0];
numStepNumOccStart = find(diff(idxStepNum) == 1);
numStepNumOccEnd = find(diff(idxStepNum) == -1);
numStepNumOccEnd(end) = length(data.(fldNames{1}));
elseif idxStepNum(1) ~= 0 && idxStepNum(end) ~= 0
idxStepNum = [0; idxStepNum; 0];
numStepNumOccStart = find(diff(idxStepNum) == 1);
numStepNumOccEnd = find(diff(idxStepNum) == -1);
numStepNumOccEnd(end) = length(data.(fldNames{1}));
else
numStepNumOccStart = find(diff(idxStepNum) == 1);
numStepNumOccEnd = find(diff(idxStepNum) == -1);
end
for jj = 1:length(numStepNumOccStart)
idxStep = [numStepNumOccStart(jj):numStepNumOccEnd(jj)];
for ii = 1:length(fldNames)
tmpVar = data.(fldNames{ii});
dataSeg(jj,1).(fldNames{ii}) = tmpVar(idxStep);
end
end
end