matthiasm@8
|
1 function outparts = makeparts(beattimes,segtimes,seglevel)
|
matthiasm@8
|
2
|
matthiasm@8
|
3 parts = struct('n',[], 'indices',[], 'letter', [],'level',[]);
|
matthiasm@8
|
4 nPart = 0;
|
matthiasm@8
|
5 nSeg = size(segtimes,1);
|
matthiasm@8
|
6
|
matthiasm@8
|
7 for iSeg = 1:nSeg
|
matthiasm@8
|
8 newpart = true;
|
matthiasm@8
|
9 % tempbeat = struct([]);
|
matthiasm@8
|
10 segbeats = find(mean(beattimes,2) >= segtimes(iSeg,1) & mean(beattimes,2) < segtimes(iSeg,2));
|
matthiasm@8
|
11 lenSegbeats = length(segbeats);
|
matthiasm@8
|
12 for iPart = 1:nPart
|
matthiasm@8
|
13 if seglevel(iSeg) == parts(iPart).level && lenSegbeats == parts(iPart).n
|
matthiasm@8
|
14 parts(iPart).indices = [parts(iPart).indices segbeats(1)];
|
matthiasm@8
|
15 % parts(iPart).beat = [parts(iPart).beat tempbeat];
|
matthiasm@8
|
16 newpart = false;
|
matthiasm@8
|
17 break;
|
matthiasm@8
|
18 else
|
matthiasm@8
|
19 newpart = true;
|
matthiasm@8
|
20 end
|
matthiasm@8
|
21 end
|
matthiasm@8
|
22 if newpart && ~isempty(segbeats)
|
matthiasm@8
|
23 nPart = nPart + 1;
|
matthiasm@8
|
24 parts(nPart).indices = segbeats(1);
|
matthiasm@8
|
25 parts(nPart).n = lenSegbeats;
|
matthiasm@8
|
26 parts(nPart).level = seglevel(iSeg);
|
matthiasm@8
|
27 % parts(nPart).beat = tempbeat;
|
matthiasm@8
|
28 end
|
matthiasm@8
|
29
|
matthiasm@8
|
30 end
|
matthiasm@8
|
31 partnind = zeros(nPart,1);
|
matthiasm@8
|
32 partlen = zeros(nPart,1);
|
matthiasm@8
|
33 for iPart = 1:nPart
|
matthiasm@8
|
34 partnind(iPart) = length(parts(iPart).indices);
|
matthiasm@8
|
35 partlen(iPart) = parts(iPart).n;
|
matthiasm@8
|
36 end
|
matthiasm@8
|
37 [partind,partind] = sort(partnind.*partlen,'descend');
|
matthiasm@8
|
38 letters = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U'};
|
matthiasm@8
|
39 outparts = parts;
|
matthiasm@8
|
40 for iPart = 1:nPart
|
matthiasm@8
|
41 kPart = partind(iPart);
|
matthiasm@8
|
42 parts(kPart).letter = letters{iPart};
|
matthiasm@8
|
43 outparts(iPart) = parts(kPart);
|
matthiasm@8
|
44 end |