


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.

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 % Last Modified By: sbm on Wed Aug 18 19:36:22 2004 0011 0012 clusters = unique(assignments); % get a list of unique labels . . . 0013 numclusts = length(clusters); % 0014 clustsize = zeros(numclusts,1); % 0015 for clust = 1:numclusts % ... and count # elements assigned to each label 0016 clustsize(clust) = length(find(assignments == clusters(clust))); 0017 end 0018 0019 % create a matrix with cols [old_label num_elements] and (descending) sort on num_elemebts 0020 reassign_list = flipud(sortrows([clusters, clustsize], 2)); 0021 0022 %%%%%%%%%%%% DEBUGGING - random assignments instead of size sorted. Useful because 0023 %%%%%%%%%%%% it still gets rid of unused cluster numbers. 0024 % reassign_list(1:numclusts,1) = reassign_list(randperm(numclusts),1); 0025 0026 % . . . and use that table to translate the original assignment list 0027 reassignments = zeros(size(assignments)); 0028 for clust = 1:numclusts 0029 reassignments(find(assignments == reassign_list(clust,1))) = clust; 0030 end 0031 0032 return;