function [meancriteria,SDcriteria]=multipeak_criterion_analyzer(spd,IQI_index_row,crit_indices,plotting)
%description:  takes as input the spd result (from simulated_psc_in_noise), finds all the trials with a given interpulse interval, returns/plots the mean +/- SD of those traces
    %IQI_index_row tells which row of spd contains the IQI for each trial
    %plotting can be 0 (don't plot), 1 (plot mean crit for each IQI) or 2 (plot mean and SD crit for each IQI)
%called by: command line, IQI_estimator
%calls: no custom functions
%notes: 
%code confirmed date: dec 28, 2012

IQIs=spd(IQI_index_row,:);
meancriteria=nan(length(crit_indices),max(IQIs)+1);SDcriteria=nan(length(crit_indices),max(IQIs)+1);
for i=0:max(IQIs)
    currentcrits=spd(crit_indices,find(IQIs==i))';
    meancriteria(:,i+1)=mean(currentcrits)';
    SDcriteria(:,i+1)=std(currentcrits)';
end  

if plotting
    clr=colormap(jet(size(meancriteria,2)));
    figure, hold on
    for j=1:size(meancriteria,2)
        plot(meancriteria(:,j),'color',clr(j,:))
    end
    if plotting==2
        for k=1:size(meancriteria,2)
            plot(meancriteria(:,k)-SDcriteria(:,k),'color',clr(k,:))
            plot(meancriteria(:,k)+SDcriteria(:,k),'color',clr(k,:))
        end
    end
end