%F=frequency(x) is the vector whose components are the %frequencies with which each symbol in x appears in x, %from most frequent to least frequent. %x is assumed to be a data vector with integer components. % % Usage: % F = frequency( [ 11 11 11 11 22 22 -3 -3 4 5 11 ] )' % returns F = [ 5 2 2 1 1 ], % meaning that % the most frequent symbol ("11") appears 5 times, % the second most frequent symbol ("22") % occurs 2 times, etc. % See HUFFMANLENGTH, SORTED_KRAFT, ENTROPY, HISTO. % documented in % ftp://oz.ee.umn.edu/users/kieffer/seminar/notes3.pdf % Change log: % 1999-06-29:DAV: factored "frequency" into 2 routines, % "frequency" and "histo". % 1999-06-24:DAV: David Cary added documentation % ???:JCK: John C. Kieffer wrote original version and put online at % http://www.ee.umn.edu/users/kieffer/programs.html function F = frequency(x) minimum = min(x(:)); if( minimum < 0 ) h = histo(x(:)-minimum); else h = histo(x(:)); end; % eliminate zeros h = h( find(h) ); % sort by most-frequent-first. F = flipUD( sort(h) ); % end frequency.m.