%% This is an open source software
function matchedpatterninfo = match_ptm_20161109( mypatterninfo, patterndb,oz)
%   Here we will compare each individual series patterns to overall pattern
%   database and will add the missing patterns
  
%   Input paremeters
%   mypatterninfo --- patterninfo from all series (multi_ptm_20161107)
%   patterndb     --- allobserved patterns database
%   Output paremeter
%   matchedpatterninfo --- every series will haev same patterns ever
%   observed

%   Akbilgic 20161107

matchedpatterninfo = mypatterninfo;

%nseries=size(mypatterninfo,1); % number of series

mypool=parpool(oz.numcores);
parfor i=1:oz.nseries % for each series
    [~,missingind]=setdiff(patterndb(:,1),mypatterninfo{i,1}(:,1)); % find missing patterns
    nmissing=length(missingind);
    matchedpatterninfo{i,1}=[matchedpatterninfo{i,1};[patterndb(missingind,:) zeros(nmissing,size(mypatterninfo{1,1},2)-2)]];
    
    matchedpatterninfo{i,1}= sortrows(matchedpatterninfo{i,1},[2,1]);
      
end
delete(mypool)       

end

%%



%%
% Copyright J. Andrew Howe & Oguz Akbilgic 2015
% this code may be freely used, modified, and distributed (at no charge)
% as long as this footer remains unaltered

%% Akbilgic 20161108