how to remove unique values.

3 ビュー (過去 30 日間)
danny
danny 2013 年 10 月 3 日
コメント済み: Cedric 2013 年 10 月 3 日
Hi,
I have a vector with some repeating values, and some unique.
e.g. A = [ 1 1 2 4 4 3 4 1 5 3]
How do i remove the unique values and get this:
ans = [1 3 4]
i.e. if there are duplicates of a value, keep one copy of that value. uniques are not wanted.
i can easily use unique to remove the duplicates but i also want to remove the values that appeared once.
Thanks,
Danny

採用された回答

Cedric
Cedric 2013 年 10 月 3 日
編集済み: Cedric 2013 年 10 月 3 日
Assuming that elements of A are integers greater or equal to 1, you could do something like:
>> nonUniqueValues = find( accumarray(A.', ones(size(A))) > 1 )
nonUniqueValues =
1
3
4
EDIT: we could also imagine an approach based on diff(sort(A))==0, but I prefer the approach above.
  2 件のコメント
danny
danny 2013 年 10 月 3 日
This is a fantastic solution! Many thanks for your help!
Cedric
Cedric 2013 年 10 月 3 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by