MATLAB: Remove duplicate values, but keep the initial

vector duplicate return

For example, i have
x = [0 0 0 1 1 0 0 0 1 0 1 0]
I want the index of the first zero or one, but not the duplicates.
So the vector should become:
0 1 0 1 0 1 0
Where the indices would be '1 4 6 9 10 11 12'
Thanks

Best Answer

>> x = [0,0,0,1,1,0,0,0,1,0,1,0];
>> idx = [1,1+find(diff(x)~=0)]
idx =
1 4 6 9 10 11 12
>> vec = x(idx)
vec =
0 1 0 1 0 1 0