Mercurial > hg > c4dm-chord-transcriptions
diff evaluationtools/merge_repeats.m @ 1:8973548174c1 tip
adding tools to repo
author | christopherh |
---|---|
date | Mon, 06 May 2013 14:43:47 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/evaluationtools/merge_repeats.m Mon May 06 14:43:47 2013 +0100 @@ -0,0 +1,46 @@ + +% merge contiguous repeated chord labels in a labfile + +function [t1,t2,s] = merge_repeats(labfile, outputlabfile) + +writefile = 1; + +if nargin<2 + % if no output labfile name is given then don't write output to a file + writefile=0; +end + +t1 = []; +t2 = []; +s = {}; + +[in_t1,in_t2,in_s] = labread(labfile); + +current = in_s{1}; +temp1 = in_t1(1); + +for i=1:length(in_s)-1 + + next = in_s{i+1}; + + % if current is the same as next + if ~strcmp(current,next) + t1 = [t1; temp1]; + t2 = [t2; in_t2(i)]; + s = [s; {current}]; + current = next; + temp1 = in_t1(i+1); + end + + if i==length(in_s)-1 + t1 = [t1; temp1]; + t2 = [t2; in_t2(i+1)]; + s = [s; {current}]; + end + +end + +if writefile + + labwrite(t1,t2,s,outputlabfile); +end