Quick method to find duplicates in a matrix?

Hi guys,
Does anybody know a quick way of checking to see which elements of a matrix are duplicates?
Such as:
a = [1,2,3,4,5,5,1,6,7];
Can we have matlab return the indices of all 1's and 5's or return: 1, 5
Thanks!

1 件のコメント

José-Luis
José-Luis 2014 年 7 月 16 日
What is an element is repeated more than two times?

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

 採用された回答

Joseph Cheng
Joseph Cheng 2014 年 7 月 16 日
編集済み: Joseph Cheng 2014 年 7 月 16 日

3 投票

You can try:
[uniqueA i j] = unique(A,'first');
indexToDupes = find(not(ismember(1:numel(A),i)))
There may be some parameters in the unique() function to get exactly what you desire but i don't remember it off hand.

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 7 月 16 日
編集済み: Azzi Abdelmalek 2014 年 7 月 16 日

4 投票

a = [1,2,3,4,5,5,1,6,9];
[ii,jj,kk]=unique(a)
out=ii(histc(kk,1:numel(ii))>1)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

Dan
2014 年 7 月 16 日

コメント済み:

Dan
2014 年 7 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by