MATLAB: How to count the number of times a number appear in a vector

counthistogramnumber of times

How can I count the number of times a number appear in a vector? A=[ 1 2 3 1 1 6 3 4 2 2 1 1 1 ]
1 appears 7 times 2 appears 3 times 3 appears 3 times and on … Best Regards

Best Answer

Please try the following:
A = [ 1 2 3 1 1 6 3 4 2 2 1 1 1 ];
x = unique(A);
N = numel(x);
count = zeros(N,1);
for k = 1:N
count(k) = sum(A==x(k));
end
disp([ x(:) count ]);
HTH.
Rick