No BSD License  

Highlights from
FREQTABLE

5.0

5.0 | 4 ratings Rate this file 6 Downloads (last 30 days) File Size: 585 Bytes File ID: #6631

FREQTABLE

by Mukhtar Ullah

 

27 Dec 2004 (Updated 07 Jun 2005)

Frequency table.

| Watch this File

File Information
Description

FREQTABLE Frequency table.
  [Y,N] = FREQTABLE(X) takes a vector X and returns the unique values of
  X in theoutput Y, and the number of instances of each value in the
  output N. X can be a charachter array or cell array of strings.

Acknowledgements
This submission has inspired the following:
Rankings
MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (8)
29 Dec 2004 urs (us) schwarz

no need to use unique. for large Xs this else-code becomes faster for obvious reasons. note histc is a mexed function.

x=sort(xx(:)); % same conditioning
d=diff(x); % same conditioning
% else code
xb=x([find(d);length(x)]);
x=histc(x,xb);
table=[xb x];
just a thought, us

29 Dec 2004 Mukhtar Ullah

Thanks us! I have rewritten the file according to your suggestions. Your idea is really clever.

02 Feb 2005 Bruno Desart

Just one question: how to use this with cell array?
Many thanks in advance.

06 Feb 2005 Mukhtar Ullah

Bruno Desart,
In fact, you have pointed out a limitation:
this file can't be used for cell arrays; for cells use tabulate(statistic toolbox)

06 Jun 2005 Mukhtar Ullah

This function now supports character arrays and cell arrays of strings.

24 Jul 2006 Celia Sobrino

very smart

14 Nov 2007 meinhard ploner GMX

i changed the code line after "S=..." to:

    B = S([ 1 1+find(diff(S)) ]);

and now it works for me, too. Without the change i got the message: ??? Error using ==> vertcat
CAT arguments dimensions are not consistent.

14 Nov 2007 meinhard ploner

ok, i had a transposed vector in the last try(see last review). surely [1; 1+find(diff(S))] instead of [find(diff(S)); end] does not change anything in terms of performance ;-))

Please login to add a comment or rating.
Updates
03 Jan 2005

removed one if else statement.

03 Jan 2005

rewritten as suggested by urs schwarz.

03 Jan 2005

a typo corrected.

03 Jun 2005

Extended to support character arrays and cell arrays of strings. The interpretation of outputs has been changed to make sense.

07 Jun 2005

Fixed a serious bug! Now ignores NANs.

Tag Activity for this File
Tag Applied By Date/Time
statistics Mukhtar Ullah 22 Oct 2008 07:38:46
probability Mukhtar Ullah 22 Oct 2008 07:38:46
frequency table Mukhtar Ullah 22 Oct 2008 07:38:46
instances Mukhtar Ullah 22 Oct 2008 07:38:46

Contact us at files@mathworks.com