uniquecount.m

Version 1.3.0.0 (2.62 KB) by Lee
This matlab program (Function) will count the number of occurences for each unique number.
244 Downloads
Updated 24 Feb 2014

View License

Have you ever wondered how to find out how many of each number is in a given vector or matrix on MATLAB in one function.
Well here it is:
This function will simply count the occurences of each different number so for example if you have a vector say:

X=[3 4 5 4 5 6 7 8 7 2 2 2 2 1 9 7]
N=uniquecount(X)
Matlab would output a table and then create a vector with the occurences (in number value order so in this case 1 would be the first number with 1 occurence etc.):

N =
1 4 1 2 2 1 3 1 1

Cite As

Lee (2024). uniquecount.m (https://www.mathworks.com/matlabcentral/fileexchange/45224-uniquecount-m), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on File Operations in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.3.0.0

Table output now works! An "end" was missing from "if" statement. :)

1.2.0.0

Table output now works! I missed an "end" on "if" statement. :)

1.1.0.0

Simplified code, works for very large systems and saves lots of computational time. The table output is optional. Also we can see the unique values just underneath the occurencces output which is again optional.

1.0.0.0