I have a matrix A with integer elements from 0 to N-1.
What I need to get is vector V of length N which for each position “i” will contain number of elements equal to “i” in matrix A.
For example:
N = 6
A:
0 0 1
1 2 3
3 5 0
V:
3 2 1 2 0 1 0
What is the efficient way to do this?
My real matrix is about 10K x 10K elements and N is about 100.
Use
v = histc(A(:), 0:(N-1)). To get exactly your result, performv = v'.