MATLAB: Removing duplicates in an array

duplicateunique

If i have the following array
a =[1,1,1,2,2,1,1,6,6,6,8,8,2,2,3,3,2,2]
When i do unique(a,'stable'), i get
[1,2,6,8,3]
I want the following result
[1,2,1,6,8,2,3,2]

Best Answer

b = a(logical([1 (diff(a)~=0)]))