counting number of onesin a matrix
8 views (last 30 days)
Show older comments
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
Daniel Shub
on 27 Mar 2012
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?
Accepted Answer
Andrei Bobrov
on 27 Mar 2012
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))]
0 Comments
More Answers (0)
See Also
Categories
Find more on Install Products 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!