MATLAB: Count the number of occurances of an element using accumarray

accumarraycountfrequency

Now I am trying to find the occurance of an element in a vector using
sum(dta(:,size(dta,2))==3);
How can accumarray be used to find the frequency of elements ?
A = [7 11 2 3 4 5 4 7 7 2 1 4 1];
How can I get a result such as,
  • 7 3
  • 11 1
  • 2 2
  • 3 1
  • 4 2
and so on.
Thanks in Advance.
P.S: I looked through other threads, but did not understand how it worked. The example given was count = accumarray(A',1) and the result was a vector which was not clear to me.

Best Answer

A = [7 11 2 3 4 5 4 7 7 2 1 4 1]
[a,b,c ]=unique(A,'stable')
out=[a' accumarray(c,1)]