MATLAB: How to make matlab count

count

Hello Matlab community,
I wented to know is there a way to create a code to count how many times a number ouccers in a given matrix.
For example I would like to input:
x=input('Numeber')
=[1 2 3 4 5
1 2 3 5 6
7 2 4 3 5]
Is there a way for Matlab to count how many of each number has occured.
Please provide example Thank you so much.

Best Answer

"Is there a way for Matlab to count how many of each number has occured."
The below gives the number of counts of each unique elements in the matrix:
x =[1 2 3 4 5
1 2 3 5 6
7 2 4 3 5]
[uv,~,idx] = unique(x);
n = accumarray(idx(:),1);
% or

n = histc(x(:),uv);
% or
n = sum(x(:).' == uv,2);
Result = [uv,n] % uv - unique elements in the matrix & n - number of times each unique elements appear
Gives:
Result =
1 2
2 3
3 3
4 2
5 3
6 1
7 1
>>