Finding the index of dupplicate rows in a matrix
    6 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
I have matrix M 275935x2 . I want to remove duplicate rows. I tried two methods: Method 1)
     M2=unique(M,'rows') % and it gave M2 179109x2 double
Method 2)
x0=find(hist(M,unique(M))>1); % it gave only 8301 duplicate values.
Which method is correct? I want to find th eindices of duplicate rows and not simply remove them. Any help is appreciated
0 comentarios
Respuestas (1)
  Stephen23
      
      
 el 6 de Feb. de 2017
        
      Editada: Stephen23
      
      
 el 6 de Feb. de 2017
  
      >> A = randi(1e4,275935,2);
>> [B,~,Y] = unique(A,'rows','stable');
>> [C,X] = hist(Y,unique(Y));
>> Z = ismember(Y,X(C>1)); % indices of repeated rows of A
For example this random data set had
 >> nnz(Z)
ans =
   816
row that occur most than once. To get the indices of the duplicate rows, try this:
 [U,W] = unique(A,'rows','stable');
 D = setdiff(1:size(A,1),W); %indices of duplicate rows.
Ver también
Categorías
				Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

