Effacer les filtres
Effacer les filtres

FInding duplicates in matrices

1 vue (au cours des 30 derniers jours)
NUR KHAIRUNNISA rahimi
NUR KHAIRUNNISA rahimi le 26 Juin 2012
Dear experts, Given square matrix M, I would like to detect the position of the first duplicate. I have made the code such that it'll be able to do that across the columns, but there is something wrong somewhere in the code that shows even those who aren't duplicates and I am not sure how to fix it. Could you help point that out if possible, please? Thank you!
for ii=1:length(board)
for jj=1:length(board)
if sum((board(:,ii)==board(jj,ii)))>1
fprintf('Duplicate value(%d) found at row: %d, column: %d\n',board(ii,jj),ii,jj)
break
end
end
end
  1 commentaire
Luca Cerone
Luca Cerone le 26 Juin 2012
Hi Nur, can you explain what you mean by first duplicate?
In any case when you have to find elements in a Matrix that satisfy certain criterion
often the function "find" does what you need.

Connectez-vous pour commenter.

Réponses (1)

Honglei Chen
Honglei Chen le 26 Juin 2012
In your program, your element under test is board(jj,ii) while in the result, you are using board(ii,jj),so they are not consistent.On the other hand, your code only looks for duplicates within a column, is this what you want?

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by