function [latencies_fullepoch,critlogical_fullepoch]=find_detection_crits_and_latencies_generalizedform(criteria_fullepoch,thresh,APs_per_trial)
%description: uses the criterion matrix (measured and stored by patchfile_analysis<--create_storage_matrices) to determine whether synaptic current followed an AP, and if so at what latency
%called by: analyze_across_expts, convert_stored_matrix, analyze_across_sd_stdp_expts(deprecated)
%calls: no custom functions
%notes:
%code confirmed date: oct 6, 2009

if rem(size(criteria_fullepoch,1),APs_per_trial),error('How many APs?'),end  %this will catch *some* errors where APs_per_trial is incorrect
indivcritlength=size(criteria_fullepoch,1)/APs_per_trial;

latencies_fullepoch=[];
critz=[];
for i=1:APs_per_trial
    rowsthisAP=[(((i-1)*indivcritlength)+1):(i*indivcritlength)];
	c=criteria_fullepoch(rowsthisAP,:)>thresh;
	[maxval,maxind]=max(c);
	maxind(~maxval)=0;
    latencies_fullepoch=[latencies_fullepoch;maxind]; %latency of 0 means criterion never exceeded threshold in this chunk of time
    critz=[critz;maxval];
end
critlogical_fullepoch=logical(critz);