Clear Filters
Clear Filters

Finding the Frequency of Unique Values

19 views (last 30 days)
How to return the frequency of each value in array A? (So, B views there are 3, 1, 4, and 2 of 1, 2, 3, and 4, respectively)
A = [ 1 1 4 3 3 3 3 2 4 1 ]
B = [ 3 1 4 2]

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 13 Aug 2016
Edited: Azzi Abdelmalek on 13 Aug 2016
A = [ 1 1 4 3 3 3 3 2 4 1 ]
[ii,jj,kk]=unique(A)
freq=accumarray(kk,1)
out=[ii' freq]
%or
freq=hist(A,1:4)

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!