function analyze_sd(lookat_preinduc_ao_induc_ao_postinduc,pscmat,trialcountmat,critz,latenciez,minutes_per_trial,APs_per_trial,casecolor,patchtitle,number_of_cases,presentcase);
%the urge to make a master analysis was suppressed, but the urge to avoid hours of tedious cutting and pasting ultimately held sway, resulting in the creation of a 'master analysis' as of dec 2006
%and then an 'even more master' analysis was created, analyze_across_sd_stdp_expts, which calls this routine
%reading 'lookat_preinduc_ao_induc_ao_postinduc': %1 is preinduc only, 2 is induc only, 3 is postinduc only, 7 is all three

psc_values=pscmat(3:end,:);  %because only the first two IPIs are stored for the four pulse trials used in 2007, this is general
array_to_use=psc_values;
preinduc_trials=1:trialcountmat(1);
postinduc_trials=(trialcountmat(1)+1):(trialcountmat(1)+trialcountmat(2));

if APs_per_trial==3
    possible_IPIs=[400]; %[12.5 25 50 100 150 200 400 800]
    ipis_preinduction=pscmat(1,preinduc_trials);ipis_postinduction=pscmat(1,postinduc_trials);%take from row 1 to get IPIa, take from row two to get IPIb
    rowaa=2;rowbb=2;rowcc=1;rowdd=1;
    values_alpha=array_to_use(rowaa,preinduc_trials);values_beta=array_to_use(rowbb,postinduc_trials);
    values_gamma=array_to_use(rowcc,preinduc_trials);values_delta=array_to_use(rowdd,postinduc_trials);
    crits_alpha=critz(rowaa,preinduc_trials);crits_beta=critz(rowbb,postinduc_trials);
    crits_gamma=critz(rowcc,preinduc_trials);crits_delta=critz(rowdd,postinduc_trials);
    preinduction_normalizer=mean(array_to_use(1,preinduc_trials));postinduction_normalizer=mean(array_to_use(1,postinduc_trials));
elseif APs_per_trial==4
    possible_IPIs=[400]; %[50 400]
    ipis_preinduction=pscmat(1,preinduc_trials);ipis_postinduction=pscmat(1,postinduc_trials); %take from row 1 to get IPIa, take from row two to get IPIb, take from row 3 to get IPIc
    rowee=2;rowff=2;rowgg=1;rowhh=1;
    values_alpha=array_to_use(rowee,preinduc_trials);values_beta=array_to_use(rowff,postinduc_trials);
    values_gamma=array_to_use(rowgg,preinduc_trials);values_delta=array_to_use(rowhh,postinduc_trials);
    crits_alpha=critz(rowee,preinduc_trials);crits_beta=critz(rowff,postinduc_trials);
    crits_gamma=critz(rowgg,preinduc_trials);crits_delta=critz(rowhh,postinduc_trials);
    preinduction_normalizer=mean(array_to_use(1,preinduc_trials));postinduction_normalizer=mean(array_to_use(1,postinduc_trials));
end

figure(55)
for current_IPI=1:length(possible_IPIs)
    okra=find(possible_IPIs(current_IPI)==ipis_preinduction);
    pakora=find(possible_IPIs(current_IPI)==ipis_postinduction);
    if ~isempty(okra) && ~isempty(pakora)
        
%       for potency  
%         placeholder_xaxis=repmat(nan,1,length(ipis_preinduction));
% 		placeholder_xaxis(okra)=values_alpha(okra);
% 		placeholder_xaxis=placeholder_xaxis./crits_alpha; %s.t. only those that succeeded on psca get through
% 		almostfinalxaxis=placeholder_xaxis./~crits_gamma;   %s.t. only those that failed on psco get through
% 		almostfinalxaxis=almostfinalxaxis(~isnan(almostfinalxaxis));
%         finalxval=almostfinalxaxis(~isinf(almostfinalxaxis));
%         placeholder_yaxis=repmat(nan,1,length(ipis_preinduction));
% 		placeholder_yaxis(okra)=values_alpha(okra);
% 		placeholder_yaxis=placeholder_yaxis./crits_alpha;
% 		almostfinalyaxis=placeholder_yaxis./crits_gamma;
% 		almostfinalyaxis=almostfinalyaxis(~isnan(almostfinalyaxis));
%         finalyval=almostfinalyaxis(~isinf(almostfinalyaxis));
        placeholder_xaxis=repmat(nan,1,length(ipis_postinduction));
		placeholder_xaxis(pakora)=values_beta(pakora);
		placeholder_xaxis=placeholder_xaxis./crits_beta; %s.t. only those that succeeded on psca get through
		almostfinalxaxis=placeholder_xaxis./~crits_delta;   %s.t. only those that failed on psco get through
		almostfinalxaxis=almostfinalxaxis(~isnan(almostfinalxaxis));
        finalxval=almostfinalxaxis(~isinf(almostfinalxaxis));
        placeholder_yaxis=repmat(nan,1,length(ipis_postinduction));
		placeholder_yaxis(pakora)=values_beta(pakora);
		placeholder_yaxis=placeholder_yaxis./crits_beta;
		almostfinalyaxis=placeholder_yaxis./crits_delta;
		almostfinalyaxis=almostfinalyaxis(~isnan(almostfinalyaxis));
        finalyval=almostfinalyaxis(~isinf(almostfinalyaxis));
             
        %for Pr
%         critsatthisinterval=crits_alpha(okra);                                                                                                                                
%         finalxval=length(find(critsatthisinterval(find(~crits_gamma(okra)))))/length(critsatthisinterval(find(~crits_gamma(okra))));
%         finalyval=length(find(critsatthisinterval(find(crits_gamma(okra)))))/length(critsatthisinterval(find(crits_gamma(okra))));
% 			critsatthisinterval=crits_beta(pakora);                                                                                                                                
%             finalxval=length(find(critsatthisinterval(find(~crits_delta(pakora)))))/length(critsatthisinterval(find(~crits_delta(pakora))));
%             finalyval=length(find(critsatthisinterval(find(crits_delta(pakora)))))/length(critsatthisinterval(find(crits_delta(pakora))));

        
        %for <psc>
%         placeholder=repmat(nan,1,length(ipis_preinduction));
% 		placeholder(okra)=values_alpha(okra);
%         almostfinalxval=placeholder(find(~crits_gamma));
%         finalxval=almostfinalxval(~isnan(almostfinalxval));
%         almostfinalyval=placeholder(find(crits_gamma));
%         finalyval=almostfinalyval(~isnan(almostfinalyval));
%         placeholder=repmat(nan,1,length(ipis_postinduction));
% 		placeholder(pakora)=values_beta(pakora);
%         almostfinalxval=placeholder(find(~crits_delta));
%         finalxval=almostfinalxval(~isnan(almostfinalxval));
%         almostfinalyval=placeholder(find(crits_delta));
%         finalyval=almostfinalyval(~isnan(almostfinalyval));
                                                                                                                                                                                            
        %asdf=mean(values_delta(pakora))/mean(values_beta(pakora));%if any(isnan(almostfinalxval)),error('geez'),end %if any(isnan(almostfinalyval)),error('louise'),end
        %qwer=mean(values_gamma(okra))/mean(values_alpha(okra))
        %almostfinalxval=mean(values_gamma(okra))/mean(values_alpha(okra)); 
        if ~isempty(finalxval) && ~isempty(finalyval)
            dual_errorbar_plot(mean(finalxval),std(finalxval)/sqrt(length(finalxval)),mean(finalyval),std(finalyval)/sqrt(length(finalyval)),casecolor,num2str(current_IPI))
        else
            disp('finalxval a/o finalyval empty')
        end
    else
        disp('okra a/o pakora empty')
	end
end

%--------------
% %for epoch=1:2%round(lookat_preinduc_andor_postinduc/2):floor(lookat_preinduc_andor_postinduc/2)+1
%    
% 	condition_of_first_response={'live_rowz&critz(1,:);' 'live_rowz&~critz(1,:);'};
%     linewidths=[2 3];  %to plot multiple conditions, use this line, the for loop, the eval line and change linewidths below
% 	%condition_of_second_response={'live_rowz;' live_rows&~critz(2,:);' 'live_rowz&critz(2,:);'};
%     [i,j]=find(isnan(live_psc_array(3:5,:)))
%     if ~isempty(i),error('s'),end
%     if ~isempty(j),error('s'),end
%     holdz_follows_release=[];holdz_follows_failure=[];
%     for n=1:length(condition_of_first_response)
%         holdz_all=[]; holdz_success_rates=[]; holdz_success_sizes=[]; holdz_latencies=[]; holdz_failure_sizes=[];ppr_=[];
%         for k=1:length(hy)
%             live_rowz=zeros(1,size(live_psc_array,2));
%             live_rowz(find(live_psc_array(1,:)==hy(k)))=1;
%             eval(['live_rowz=' condition_of_first_response{n}])
%             
%             %mean, SD & SEM of all pscs having the IPI in question
%             holdz_all(1,k)=mean(live_psc_array(live_psc,find(live_rowz)));
%             holdz_all(2,k)=std(live_psc_array(live_psc,find(live_rowz)));
%             holdz_all(3,k)=holdz_all(2,k)/holdz_all(1,k);
%             
%             onemeansthetrialhadthisIPI=zeros(1,size(live_psc_array,2));
%             onemeansthetrialhadthisIPI(find(live_psc_array(1,:)==hy(k)))=1;
%             psca_positive=zeros(1,size(live_psc_array,2));
%             psca_positive(find(live_psc_array(4,:)>0))=1;
%             psca_non_nan=zeros(1,size(live_psc_array,2));
%             psca_non_nan(find(~isnan(live_psc_array(4,:))))=1;
%             
%             if n==1
%                 holdz_follows_release(k)=mean(live_psc_array(4,find(live_rowz&psca_positive&psca_non_nan)));
%             elseif n==2
%                 holdz_follows_failure(k)=mean(live_psc_array(4,find(live_rowz&psca_positive&psca_non_nan)));
%             end
%             %---
% %             onemeansthetrialhadthisIPI=zeros(1,size(live_psc_array,2));
% %             onemeansthetrialhadthisIPI(find(live_psc_array(1,:)==hy(k)))=1;
% %             bothvals_positive=zeros(1,size(live_psc_array,2));
% %             bothvals_positive(find(live_psc_array(3,:)>0 & live_psc_array(4,:)>0))=1;
% %             ppr_(1,k)=mean(live_psc_array(4,find(critz(1,:)&critz(2,:)&onemeansthetrialhadthisIPI&bothvals_positive))./live_psc_array(3,find(critz(1,:)&critz(2,:)&onemeansthetrialhadthisIPI&bothvals_positive)));
% %             ppr_(2,k)=std(live_psc_array(4,find(critz(1,:)&critz(2,:)&onemeansthetrialhadthisIPI&bothvals_positive))./live_psc_array(3,find(critz(1,:)&critz(2,:)&onemeansthetrialhadthisIPI&bothvals_positive)));
% %             ppr_(3,k)=ppr_(2,k)/ppr_(1,k);
% %             %---------
% %             figure(current_expt)
% %             if epoch==1,subplot(1,60,[1:29]),elseif epoch==2,subplot(1,60,[31:60]),end
% % %             subplot(1,2,epoch)
% %             hh=live_psc_array(3:5,find(onemeansthetrialhadthisIPI))
% %             hh_mean(1:3)=mean(hh')./mean(hh(1,:))
% %             hh_std(1:3)=std(hh')./std(hh(1,:))
% %             hh_sem(1:3)=hh_std./hh_mean
% %             linez=[.5 1 1.5 2 2.5];
% %             plot([1:3],hh_mean,linestyle,'color',casecolor,'linewidth',linez(k),'markersize',7,'markerfacecolor',casecolor), hold on
% %             for m=1:3  %plotting error bars on holds all
% %                 %plot([m m],[hh_mean(m)-hh_sem(m) hh_mean(m)+hh_sem(m)],'color',casecolor,'linewidth',3)
% %                 %plot([m m],[holdz_all(1,m)-holdz_all(2,m) holdz_all(1,m)+holdz_all(2,m)],'color',casecolor,'linewidth',3)
% %             end 
% %             xlim([0 4]), %set(gca,'xtick',[],'ytick',[])
%             %-----------
%             
%             %success rates
%             holdz_success_rates(1,k)=length(find(live_rowz&critz(2,:)))/length(find(live_rowz));
%             
%             %success sizes
%             holdz_success_sizes(1,k)=mean(live_psc_array(live_psc,find(live_rowz&critz(2,:))));
%             holdz_success_sizes(2,k)=std(live_psc_array(live_psc,find(live_rowz&critz(2,:))));
%             holdz_success_sizes(3,k)=holdz_success_sizes(2,k)/holdz_success_sizes(1,k);
%             
%             %latencies
%             latency_temp=latenciez(psc_being_plotted,find(live_rowz));
%             latency_temp(find(~latency_temp))=[];
%             if ~isempty(latency_temp)
%                 holdz_latencies(1,k)=mean(latency_temp);
%                 holdz_latencies(2,k)=std(latency_temp);
%                 holdz_latencies(3,k)=holdz_latencies(2,k)/holdz_latencies(1,k);
%             else
%                 holdz_latencies(1,k)=nan;
%                 holdz_latencies(2,k)=nan;
%                 holdz_latencies(3,k)=nan;
%             end
%             
%             %failure sizes
%             holdz_failure_sizes(1,k)=mean(live_psc_array(live_psc,find(live_rowz&~critz(2,:))));
%             holdz_failure_sizes(2,k)=std(live_psc_array(live_psc,find(live_rowz&~critz(2,:))));
%             holdz_failure_sizes(3,k)=holdz_failure_sizes(2,k)/holdz_failure_sizes(1,k);
%         end
%         
% %         figure(current_expt)
% %         plot([1:length(hy)],holdz_all(1,:),linestyle,'color',casecolor,'linewidth',epoch+1,'markersize',7,'markerfacecolor',markfacecolor), hold on
% %         for m=1:length(hy)  %plotting error bars on holds all
% %             plot([m m],[holdz_all(1,m)-holdz_all(3,m) holdz_all(1,m)+holdz_all(3,m)],'color',casecolor,'linewidth',3)
% %             %plot([m m],[holdz_all(1,m)-holdz_all(2,m) holdz_all(1,m)+holdz_all(2,m)],'color',casecolor,'linewidth',3)
% %         end 
% %         xlim([0 6]), set(gca,'xtick',[])
% %         figure(current_expt)
% %         plot([1:length(hy)],ppr_(1,:),linestyle,'color',casecolor,'linewidth',epoch+1,'markersize',7,'markerfacecolor',markfacecolor), hold on
% %         for m=1:length(hy)  %plotting error bars on holds all
% %             plot([m m],[ppr_(1,m)-ppr_(3,m) ppr_(1,m)+ppr_(3,m)],'color',casecolor,'linewidth',3)
% %             %plot([m m],[holdz_all(1,m)-holdz_all(2,m) holdz_all(1,m)+holdz_all(2,m)],'color',casecolor,'linewidth',3)
% %         end 
% %         xlim([0 6]), set(gca,'xtick',[]), set(gca,'ytick',[0:10])
%         
%         %plot holdz_all
%         %subplot(3,number_of_cases,current_expt), set(gca,'xtick',[])
% %         figure(current_expt)
% %         plot([1:length(hy)],holdz_all(1,:),linestyle,'color',casecolor,'linewidth',epoch+1,'markersize',7,'markerfacecolor',markfacecolor), hold on
% %         for m=1:length(hy)  %plotting error bars on holds all
% %             plot([m m],[holdz_all(1,m)-holdz_all(3,m) holdz_all(1,m)+holdz_all(3,m)],'color',casecolor,'linewidth',3)
% %             %plot([m m],[holdz_all(1,m)-holdz_all(2,m) holdz_all(1,m)+holdz_all(2,m)],'color',casecolor,'linewidth',3)
% %         end 
% %         xlim([0 6]), set(gca,'xtick',[])
%         %plotting success rates
% %         subplot(3,number_of_cases,current_expt+number_of_cases), set(gca,'xtick',[])
% %         plot([1:length(hy)],holdz_success_rates(1,:),linestyle,'color',casecolor,'linewidth',linewidths(n),'markersize',7,'markerfacecolor',markfacecolor), hold on  
% %         %plotting success sizes
% %         subplot(3,number_of_cases,current_expt+2*number_of_cases), set(gca,'xtick',[])
% %         plot([1:length(hy)],holdz_success_sizes(1,:),linestyle,'color',casecolor,'linewidth',linewidths(n),'markersize',7,'markerfacecolor',markfacecolor), hold on
% %         for m=1:length(hy)  %plotting error bars on holds all
% %             plot([m m],[holdz_success_sizes(1,m)-holdz_success_sizes(3,m) holdz_success_sizes(1,m)+holdz_success_sizes(3,m)],'color',casecolor,'linewidth',3)
% %         end
% %         %plotting latency
% %         subplot(5,number_of_cases,current_expt+3*number_of_cases), set(gca,'xtick',[])
% %         holdz_latencies=holdz_latencies/10; %converting to ms
% %         plot([1:length(hy)],holdz_latencies(1,:),linestyle,'color',casecolor,'linewidth',linewidths(n),'markersize',7,'markerfacecolor',markfacecolor), hold on
% %         for m=1:length(hy)  %plotting error bars on holds all
% %             plot([m m],[holdz_latencies(1,m)-holdz_latencies(3,m) holdz_latencies(1,m)+holdz_latencies(3,m)],'color',casecolor,'linewidth',3)
% %         end
% %         ylim([0 10])
% %         %plotting failure sizes
% %         subplot(5,number_of_cases,current_expt+4*number_of_cases)
% %         plot([1:length(hy)],holdz_failure_sizes(1,:),linestyle,'color',casecolor,'linewidth',linewidths(n),'markersize',7,'markerfacecolor',markfacecolor), hold on
% %         for m=1:length(hy)  %plotting error bars on holds all
% %             plot([m m],[holdz_failure_sizes(1,m)-holdz_failure_sizes(3,m) holdz_failure_sizes(1,m)+holdz_failure_sizes(3,m)],'color',casecolor,'linewidth',3)
% %         end
% % %         %holdz_success_rates(find(holdz_success_rates==1))=nan;
% % %         [latz,ii]=sort(holdz_latencies(1,:));sucsrat=[];shh=[];for z=1:5,sucsrat(z)=holdz_all(1,ii(z));shh(z)=holdz_success_sizes(1,ii(z));end
% % %         figure(5),plot(latz,sucsrat,linestyle,'color','k','linewidth',linewidths(n),'markersize',15),hold on%,'markerfacecolor',markfacecolor),hold on
% % %         %figure(5),plot(holdz_latencies(1,:),holdz_success_rates,'ko-','markersize',15,'linewidth',2),hold on
% % %         figure(6),plot(holdz_success_rates,shh,'ko-','markersize',15,'linewidth',2),hold on
% % %         figure(1)
% 	end
%        
%     abb=holdz_follows_release
%     babb=holdz_follows_failure
%     cabb=abb./babb
% %     a=isnan(holdz_follows_release)
% %     b=isnan(holdz_follows_failure)
% %     c=a|b
% %     
% %     abb(c)=[]
% %     babb(c)=[]
% %     
% %     fr25=holdz_follows_release(1);fr50=holdz_follows_release(2);fr100=holdz_follows_release(3);fr200=holdz_follows_release(4);fr400=holdz_follows_release(5);
% %     ff25=holdz_follows_failure(1);ff50=holdz_follows_failure(2);ff100=holdz_follows_failure(3);ff200=holdz_follows_failure(4);ff400=holdz_follows_failure(5);
% %     if ~isnan(fr25)&~isnan(ff25)
% %         holholder(1)=(fr25/ff25)
%         
% %     abb(find(isnan(holdz_follows_failure)))=[];
% %     babb(find(isnan(holdz_follows_failure)))=[];
%         
%     holdzforreal=abb./babb%(holdz_follows_release-holdz_follows_failure)./holdz_follows_release
%     
%     if ~isempty(holdzforreal)   
%         holdzforreal=mean(holdzforreal)
%     else
%         holdzforreal=[]
%     end
%     
%     
%     if epoch==1
%         persistent mean_pscos_before
%         mean_pscos_before=[mean_pscos_before mean(preinduction_psc(3,:))];
%         mean_psc_o_before=mean(preinduction_psc(3,:));
%         persistent p_noughts_before
% 		p_noughts_before=[p_noughts_before length(find(crit_o_pre))/length(crit_o_pre)];
%         persistent mean_size_success_before
%         mean_size_success_before=[mean_size_success_before mean(preinduction_psc(3,find(crit_o_pre)))];
%         persistent ppr25s_before
%         ppr25s_before=[ppr25s_before mean(preinduction_psc(4,find(crit_o_pre&crit_a_pre&(preinduction_psc(1,:)==25))))/mean(preinduction_psc(3,find(crit_o_pre&crit_a_pre&(preinduction_psc(1,:)==25))))];
%         persistent ppr400s_before
%         abra=preinduction_psc(4,find(crit_o_pre&crit_a_pre&(preinduction_psc(1,:)==400)));
%         cad=preinduction_psc(3,find(crit_o_pre&crit_a_pre&(preinduction_psc(1,:)==400)));
%         abbra=abra/cad;
%         ppr400s_before=[ppr400s_before mean(preinduction_psc(4,find(crit_o_pre&crit_a_pre&(preinduction_psc(1,:)==400))))/mean(preinduction_psc(3,find(crit_o_pre&crit_a_pre&(preinduction_psc(1,:)==400))))];
%         if abbra>10,ppr400s_before(current_expt)=nan,end
%         persistent holdzforrealpreinduc
%         holdzforrealpreinduc=[holdzforrealpreinduc holdzforreal]
%         persistent holderbyipi_preinduc
%         holderbyipi_preinduc=[holderbyipi_preinduc;cabb]
%         persistent rise_pres
%         rise_pres=[rise_pres mean(preinduction_psc(3,:))]
%     elseif epoch==2
%         mean_psc_o_after=mean(postinduction_psc(3,:));
%         persistent mean_size_success_after
%         mean_size_success_after=[mean_size_success_after mean(postinduction_psc(3,find(crit_o_post)))];
%         persistent p_noughts_after
% 		p_noughts_after=[p_noughts_after length(find(crit_o_post))/length(crit_o_post)];
%         persistent holdzforrealpostinduc
%         holdzforrealpostinduc=[holdzforrealpostinduc holdzforreal]
%         persistent holderbyipi_postinduc
%         holderbyipi_postinduc=[holderbyipi_postinduc;cabb]
%     end
% end
% 
% persistent stdp_ratios
% stdp_ratios=[stdp_ratios mean(postinduction_psc(3,:))/mean(preinduction_psc(3,:))]