MATLAB: Non-Sorted nx1 unique values

indexingmatrix

Hello, i am attempting to find repeated values in an nx1 matrix, the catch is that the unique function sorts the data. The data should not be sorted. Ideally i would like the output from my mystery function to be 1 for not repeated and 0 for repeated. Any suggestions?!
input: [1;1;1;2;3;4;5;6;6;7] output:[1;0;0;1;1;1;1;1;0;1]
the idea is that i can multiply the output and the original matrix where the data resides so that duplicate records will show as 0 values, but the first stays!
Thanks again! If you would like me to post another question please let me know!

Best Answer

Let x be the given n by 1 vector.
[y,p] = sort(x);
d = diff(y)~=0;
b = [d;true] & [true;d];
b(p) = b;
Then b will be your "ideal" desired result.