counting number of onesin a matrix

i have a matrix
A=[1 2 3;1 1 2;3 3 2]
from these i wwant to count number of 1's,2;s,3's
please help

1 Comment

This is very similar to your previous question: http://www.mathworks.com/matlabcentral/answers/33405-counting-the-values-and-variables
What have you tried so far? Where are you stuck?

Sign in to comment.

 Accepted Answer

a = unique(A);
out = [a, histc(A(:),a)];
OR in rows:
a = unique(A)'
outrws = [a;cell2mat(arrayfun(@(x)histc(A(x,:),a),(1:size(A,1))','un',0))]
in columns
a = unique(A)
outcls = [a,cell2mat(arrayfun(@(x)histc(A(:,x),a),1:size(A,2),'un',0))]

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!