0001 function overlap=bml_annot_overlap(cfg, annot)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 if nargin == 1
0015 annot = cfg;
0016 cfg=[];
0017 elseif nargin ~= 2
0018 error('incorrect number of arguments');
0019 end
0020
0021 timetol = bml_getopt(cfg,'timetol',1e-5);
0022 annot = bml_annot_table(annot);
0023
0024 i=1; j=2;
0025 overlap = cell2table(cell(0,4));
0026 overlap.Properties.VariableNames = {'starts','ends','id1','id2'};
0027 while i<=height(annot) && j<=height(annot)
0028
0029 if annot.ends(j) - annot.starts(i) > timetol && ...
0030 annot.ends(i) - annot.starts(j) > timetol
0031 overlap = [overlap;{...
0032 max(annot.starts(i),annot.starts(j)),...
0033 min(annot.ends(i),annot.ends(j)),...
0034 annot.id(i),...
0035 annot.id(j)}];
0036 j = j + 1;
0037 elseif annot.ends(i) - annot.starts(j) <= timetol
0038 i=i+1;
0039 j=i+1;
0040 elseif annot.ends(j) - annot.starts(i) <= timetol
0041 j=j+1;
0042 else
0043 annot([i j],:)
0044 error('Unsupported input annotations tables');
0045 end
0046 end