Unique (indices) method similar to MATLAB

For completeness, perhaps this thread should mention GroupSlices.jl (not written by me!) which in fact doesn’t return Matlab’s 3rd output:

A = [9, 2, 9, 5];
C = unique(A)
ia = unique(i -> A[i], 1:length(A)) # [1, 2, 4]
A[ia] == C
using GroupSlices
ig = groupslices(A) # [1, 2, 1, 4]
A[ig] == A # not matlab's ic
ia == firstinds(ig)
4 Likes