Revision 1732ada9c8b7f1432fe3fd494fa00a27e29425ff authored by simkind on 16 March 2024, 19:13:22 UTC, committed by GitHub on 16 March 2024, 19:13:22 UTC
1 parent 7a7d099
AUCStartFinder.m
% AHPstart_time = Results(sweep).AHPstart_time
function [AUCstartidx] = AUCStartFinder(data,si,bl,startsearch)
start_idx = startsearch; %startsearchtime/(si/1000); being the search at the stop idx of baseline
% start_idx = str2double(sprintf('%16.f',start_idx));
% if ~isempty(AHPstart_idx) % if there is an AHPstart - but you can do this in the script
numconsecreturn = 10/(si/1000);
aboveblidx = find(data(start_idx:end) >= bl); % find data points above baseline after start_idx
if ~isempty(aboveblidx) && length(aboveblidx) > numconsecreturn % if there are points above
diffbtwn = diff(aboveblidx); % if consecutive bins are above threshold, diff should be 1 for each
possible = [];
counter = 1;
while isempty(possible)
if sum(diffbtwn(counter:counter+numconsecreturn-1)) == numconsecreturn
possible = counter;
end
counter = counter + 1;
if counter >= length(diffbtwn)-numconsecreturn
break
end
end
if ~isempty(possible) % if there is AUC start point that meets criteria
AUCstartidx = start_idx+aboveblidx(possible);
else % if there isn't an AUC start idx
figure, plot(data) % to show why
error('Could not detect AUC start idx');
end
else
error('Not enough data points are above baseline for specified minimum duration to detect AUC start idx')
end
end
Computing file changes ...