annotate evaluationtools/merge_repeats.m @ 1:8973548174c1 tip

adding tools to repo
author christopherh
date Mon, 06 May 2013 14:43:47 +0100
parents
children
rev   line source
christopherh@1 1
christopherh@1 2 % merge contiguous repeated chord labels in a labfile
christopherh@1 3
christopherh@1 4 function [t1,t2,s] = merge_repeats(labfile, outputlabfile)
christopherh@1 5
christopherh@1 6 writefile = 1;
christopherh@1 7
christopherh@1 8 if nargin<2
christopherh@1 9 % if no output labfile name is given then don't write output to a file
christopherh@1 10 writefile=0;
christopherh@1 11 end
christopherh@1 12
christopherh@1 13 t1 = [];
christopherh@1 14 t2 = [];
christopherh@1 15 s = {};
christopherh@1 16
christopherh@1 17 [in_t1,in_t2,in_s] = labread(labfile);
christopherh@1 18
christopherh@1 19 current = in_s{1};
christopherh@1 20 temp1 = in_t1(1);
christopherh@1 21
christopherh@1 22 for i=1:length(in_s)-1
christopherh@1 23
christopherh@1 24 next = in_s{i+1};
christopherh@1 25
christopherh@1 26 % if current is the same as next
christopherh@1 27 if ~strcmp(current,next)
christopherh@1 28 t1 = [t1; temp1];
christopherh@1 29 t2 = [t2; in_t2(i)];
christopherh@1 30 s = [s; {current}];
christopherh@1 31 current = next;
christopherh@1 32 temp1 = in_t1(i+1);
christopherh@1 33 end
christopherh@1 34
christopherh@1 35 if i==length(in_s)-1
christopherh@1 36 t1 = [t1; temp1];
christopherh@1 37 t2 = [t2; in_t2(i+1)];
christopherh@1 38 s = [s; {current}];
christopherh@1 39 end
christopherh@1 40
christopherh@1 41 end
christopherh@1 42
christopherh@1 43 if writefile
christopherh@1 44
christopherh@1 45 labwrite(t1,t2,s,outputlabfile);
christopherh@1 46 end