countUnique

PURPOSE ^

countUnique Count unique elements in a vector (cell array or numerical)

SYNOPSIS ^

function [sortedList,sortedCount] = countUnique(list)

DESCRIPTION ^

countUnique Count unique elements in a vector (cell array or numerical)
 Also sorts the unique elements in descending order

 [sortedList,sortedCount] = countUnique(list)

 Markus Herrgard 3/17/07

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [sortedList,sortedCount] = countUnique(list)
0002 %countUnique Count unique elements in a vector (cell array or numerical)
0003 % Also sorts the unique elements in descending order
0004 %
0005 % [sortedList,sortedCount] = countUnique(list)
0006 %
0007 % Markus Herrgard 3/17/07
0008 
0009 [uniqList,tmp,index] = unique(list);
0010 
0011 for i = 1:length(uniqList)
0012     count(i) = sum(index == i);
0013 end
0014 
0015 [sortedCount,sortedInd] = sort(count,2,'descend');
0016 
0017 sortedList = uniqList(sortedInd);
0018 
0019 sortedCount = columnVector(sortedCount);

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003