-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadaptQuickSort.m
More file actions
32 lines (26 loc) · 971 Bytes
/
adaptQuickSort.m
File metadata and controls
32 lines (26 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function data = adaptQuickSort(data, nClusters)
peakLimit = 2;
peakIncrementFactor = 1.1;
limitOK = false;
while ~limitOK
qdata = quickSort(data, nClusters, peakLimit);
clusterList = unique(qdata.spikeClusters);
nSpikes = [];
for clustNn = 1:length(clusterList)
clustN = clusterList(clustNn);
nSpikes(clustN) = length(find(qdata.spikeClusters == clustN));
end
meanSpikes = mean(nSpikes(1:(end-1)));
smallestSpikes = nSpikes(end);
smallRatio = smallestSpikes/meanSpikes;
if smallRatio < .5
peakLimit = peakLimit/peakIncrementFactor;
disp(['peakLimit -> ',num2str(peakLimit)]);
elseif smallRatio > 1.5
peakLimit = peakLimit*peakIncrementFactor;
disp(['peakLimit -> ',num2str(peakLimit)]);
else
limitOK = true;
end
end
data = qdata;