MATLAB: Remove duplicates and original also

elementsrepeitionunique

so i'm having trouble trying to eliminate repetitions from my arrays. i've been using unique but can't have the first instance of the element in the return. for example:
A = 1,2,2,2,3,3,3,4,5; B = unique(A); B = 1,2,3,4,5
what i'm actually looking for is B = 1,4,5 where even the first instance of repeating elements is taken out. is this possible?
Thanks

Best Answer

Assuming that the vector A is sorted:
>> A = [1,2,2,2,3,3,3,4,5];
>> B = unique(A);
>> B(histc(A,B)<2)
ans =
1 4 5
If A is not sorted, then this is a bit more complicated:
>> A = [3,3,3,5,1,4,2,2,2,2];
>> [B,X] = unique(A);
>> Y = histc(A,B)<2;
>> A(sort(X(Y))) % in original order
ans =
5 1 4
>> A(X(Y)) % sorted
ans =
1 4 5