function  stats12 = merge_PLM_stats(stats1,stats2)

%MERGE_PLM_STATS -- Merges two structs produced by PLM_STATS into one.
%
%  stats12 = merge_PLM_stats(stats1,stats2)
%
%  Each of STATS1 and STATS2 must be produced by PLM_STATS or PLE2_STATS
%  and have identical field names.
%
%  See also PLM_STATS, PLE2_STATS, PLM_SUMMARY, PLMODEL1, PLEXP2.

%  Original coding by Alexander Petrov, UC Irvine.
%  $Revision: 1.2 $  $Date: 2003/08/19 12:01 $

fields = {...
 'group'     1 ; ...
 'zP_congr'  3 ; 'zP_incon'  3 ; 'dprime' 3 ; ...   % z-probabilities
 'accZP'     1 ; 'seqP'      1 ; ...
 'mnA_congr' 3 ; 'mnA_incon' 3 ; 'Aprime' 3 ; ...   % mean output_act
 'accA'      1 ; 'seqA'      1 ; ...
 'mnI_congr' 3 ; 'mnI_incon' 3 ; 'Iprime' 3 ; ...   % mean net_input
 'accI'      1 ; 'seqI'      1 ; ...
 'contextc'  1 ; 'contexti'  1 ; ...                % transitions
 'otherc'    1 ; 'otheri'    1 ; ...
 'sbj'       1 ; ...                  % PLE2-specific fields begin here
 'RT_congr'  3 ; 'RT_incon'  3 ; 'RT' 3 ; ...       % mean RTs
 'accRT'     1 ; 'seqRT'     1 ; ...
 
} ; % end FIELDS

stats12.group = [] ;     % avoid "Warning: uninitialized variable..."
for k = 1:size(fields,1)
   f = fields{k,1} ; dim = fields{k,2} ;
   if (isfield(stats1,f))
      val = cat(dim,getfield(stats1,f),getfield(stats2,f)) ;
      stats12 = setfield(stats12,f,val) ;
   end
end

%-- Return STATS12
%%%%% End of MERGE_PLM_STATS.M
