What is the fastest way of taking an array A
and outputing both unique(A)
[i.e. the set of unique array elements of A
] as well as the multiplicity array which takes in its i-th place the i-th multiplicity of the i-th entry of unique(A)
in A
.
That's a mouthful, so here's an example. Given A=[1 1 3 1 4 5 3]
, I want:
unique(A)=[1 3 4 5]
mult = [3 2 1 1]
This can be done with a tedious for loop, but would like to know if there is a way to exploit the array nature of MATLAB.