MATLAB Answers

Find values in list that appear exactly once

9 views (last 30 days)
Hi there,
assume, i have a list of integer values. I need a fast way to find those values in the list, that appear exactly once.
By now i have a code that finds the duplicate values and dismisses them.
list = randi(100,100,1); % Generate a list which should contain duplicate values
Is there a faster way to get the final result?
Cheers, Johannes


Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 25 Aug 2017
Edited: Stephen Cobeldick on 25 Aug 2017
How about this:
[tmp,idx] = sort(list);
idp = diff(tmp)>0;
If you are okay with getting the output sorted then it can be simplified further:
tmp = sort(list);
idp = diff(tmp)>0;

  1 Comment

Johannes Korsawe
Johannes Korsawe on 25 Aug 2017
Congrats! Thats average 36% faster than my previous code!
Thank you.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!