function [meancrit,sdcrit]=spdcrittraceplot(spdarray)
%description:takes the array generated by simulated_psc_in_noise, finds all the iterations where interevent interval was 1, 2, 3, etc., and pulls out the criterion traces from those trials
%finds the mean and mean+standard deviation waveform for each interevent interval, for waterfall plotting

max_interval=max(spdarray(8,:));

meancrit=[];
sdcrit=[];

for i=1:max_interval
    goodcols=find(spdarray(8,:)==i);
    a=spdarray(9:end,goodcols)';
    if length(goodcols)>1
        b=(mean(a))';
        c=(std(a))';
    elseif length(goodcols==1)
        b=a';
        c=zeros(length(b),1);
    else
        disp(num2str(i))
        error('no iterations with this interval')
    end
    
   meancrit=[meancrit b];
   sdcrit=[sdcrit c];
end

close all
figure,hwatermean=waterfall(meancrit');
set(gca,'xtick',[0 100 200 300 400],'xticklabel',[-10 0 10 20], 'yticklabel',[0 2 4 6 8 10])
xlabel('time relative to first event onset')
ylabel('interevent interval')
zlabel('detection criterion')

%set(hwatermean,'edgecolor','k')
%set(hwater,'facealpha',0.1)
%set(hwater,'edgealpha',0.1)

figure,hwaterstd=waterfall(sdcrit');
%set(hwaterstd,'edgecolor','k')


    