function [invout, Occur] = uniquef (inv)

z = sort(inv);

[sZ,M,~] = unique(z, 'first');


M2 = [M(2:end); numel(z)+1];
Occur = M2-M; 

[Occur, IX ] = sort(Occur, 'descend');
invout = sZ(IX);

end