Home > chronux_2_00 > spikesort > helper > sortAssignments.m

sortAssignments

PURPOSE ^

SORTASSIGNMENTS Renumbers assignments

SYNOPSIS ^

function reassignments = sortAssignments(assignments)

DESCRIPTION ^

 SORTASSIGNMENTS  Renumbers assignments
    reassignments = sortAssignments(assignments)

 Takes a list of assignment numbers and reassigns label numbers such
   that the largest size group is assigned label '1', the next largest
   is assigned label '2', and so on.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function reassignments = sortAssignments(assignments)
0002 
0003 % SORTASSIGNMENTS  Renumbers assignments
0004 %    reassignments = sortAssignments(assignments)
0005 %
0006 % Takes a list of assignment numbers and reassigns label numbers such
0007 %   that the largest size group is assigned label '1', the next largest
0008 %   is assigned label '2', and so on.
0009 
0010 clusters = unique(assignments);  % get a list of unique labels . . .
0011 numclusts = length(clusters);    %
0012 clustsize = zeros(numclusts,1);  %
0013 for clust = 1:numclusts          % ... and count # elements assigned to each label
0014     clustsize(clust) = length(find(assignments == clusters(clust)));
0015 end
0016 
0017 % create a matrix with cols [old_label  num_elements] and (descending) sort on num_elemebts
0018 reassign_list = flipud(sortrows([clusters, clustsize], 2));
0019 
0020 %%%%%%%%%%%% DEBUGGING - random assignments instead of size sorted.  Useful because
0021 %%%%%%%%%%%%             it still gets rid of unused cluster numbers.
0022 % reassign_list(1:numclusts,1) = reassign_list(randperm(numclusts),1);
0023 
0024 % . . . and use that table to translate the original assignment list
0025 reassignments = zeros(size(assignments));
0026 for clust = 1:numclusts
0027     reassignments(assignments == reassign_list(clust,1)) = clust;
0028 end
0029 
0030 return;

Generated on Fri 15-Aug-2008 11:35:42 by m2html © 2003