function output=speakerSetMerge(speakerSet1, speakerSet2); % speakerSetMerge: Merge two speakerSet name1={speakerSet1.name}; num1=length(speakerSet1); name2={speakerSet2.name}; num2=length(speakerSet2); output=speakerSet1; for i=1:length(speakerSet2) index=find(strcmp(speakerSet2(i).name, name1)); if isempty(index) output(end+1)=speakerSet2(i); else % Existing speaker, merge sentence sentenceNum=length(speakerSet2(i).sentence); output(index).sentence(end+1:end+sentenceNum)=speakerSet2(i).sentence; end end