Add a third output argument "nb" to the function "unique" to return the number of occurences
Reported by Guillaume AZEMA
-- Bug description --
It is often useful when using the function unique, to "count" how many times each value was found in the initial matrix.
--> Add a third output argument "nb" to the function "unique" :
[N [,k,nb]]=unique(M)
M = initial matrix
N = unique values inside M
k = index in M of the first occurence of the unique value
nb = number of times each unique value was found in M
Example :
A = [ 4 1 2 4 7 8 7]
[N ,k,nb]=unique(M)
N = [1 2 4 7 8];
k = [2 3 1 5 6];
nb= [1 1 2 2 1];
I've looked at the code of unique and it is easily doable.
line 16 :
keq = find( x(2:$) == x(1:$-1) );
add the 2 following lines :
I = find( [x(2:$),x($)-1] ~= x(1:$));
nb = [I(1) , I(2:$)-I(1:$-1)];
-- Scilab error message --
-- How to reproduce the bug --