Remove all elements that occur more than once in a vector

Hello, I need to take a vector and remove any element that is repeated. I have tried unique(vector) but that only makes sure that each element is not repeated. I've considered comparing a number with the rest of the vector, but I can't come up with a way to do that generically. Could anyone point me in the right direction?

 Accepted Answer

Input = [1,2,2,3,4,1,5,2,7];
x = sort(Input);
ii = [ find(x(1:end-1) ~= x(2:end)) length(x) ];
l = diff([ 0 ii ]);
v = x(ii);
Output = v(l==1) % only the numbers which appear once

More Answers (1)

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

on 30 Jan 2019

Edited:

on 30 Jan 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!