Quick method to find duplicates in a matrix?

조회 수: 53 (최근 30일)
Dan
Dan 2014년 7월 16일
댓글: Dan 2014년 7월 16일
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일
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일
a = [1,2,3,4,5,5,1,6,9];
[ii,jj,kk]=unique(a)
out=ii(histc(kk,1:numel(ii))>1)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by