No BSD License  

Highlights from
Check Distribution

4.0

4.0 | 1 rating Rate this file 1 Download (last 30 days) File Size: 1.42 KB File ID: #21747

Check Distribution

by Abhisek Ukil

 

15 Oct 2008 (Updated 15 Oct 2008)

Function to check distribution of unique elements in a vector or matrix.

| Watch this File

File Information
Description

Function to check distribution of unique elements in a vector or matrix.

result=checkdistribution(x)

'result' would be a 2-column matrix, column 1 indicating which unique
numbers are present (in ascending manner), column 2 indicating how many
of them. Sum of column 2 gives total number of elements in x.
Also, plots the result, no. of apperance vs. unique elements.
It is useful for integer vector/matrix with repeatations. For effective
use in float vector/matrix, one has to round the float vector/matrix
before checking the distribution.

Example: result=checkdistribution([1,1,2,2,2,3,3,3,3,10])
result =

     1 2
     2 3
     3 4
    10 1

i.e., there are two 1's, three 2's, four 3's and one 10 in x.

If x is a string, the result includes the ASCII values of the letters,
and their countings. ASCII table can be found: www.asciitable.com

Example: result=checkdistribution('apple')
result =

    97 1
   101 1
   108 1
   112 2

i.e., one 'a'(97), 'e'(101), 'l'(108), and two 'p'(112).

MATLAB release MATLAB 7.3 (R2006b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
15 Oct 2008 Jos x@y.z

Well done, as it includes a readable help section, H1 line, examples. This makes it user friendly!
It lacks some checks on the inputs, and the same can be achieved using HISTC:

[ua,ia,ia] = unique(a) ;
result = [ua(:) histc(ia(:),1:numel(ua))] ;

which can deal with FP properly as well. Furthermore, you should omit the plot, as it is not really that user friendly (it creates a possible unwanted new figure or changes my current one).

I rate this as 4 stars, since it is really a (too) simple algorithm, but 1) it does what it says it does, and 2) the author should be credited for his efforts in writing a user-friendly interface!

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
distribution Abhisek Ukil 22 Oct 2008 10:24:28
number distribution Abhisek Ukil 22 Oct 2008 10:24:28
unique elements present Abhisek Ukil 22 Oct 2008 10:24:28

Contact us at files@mathworks.com