Find the common number in rows?
    4 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Patrick
 le 15 Nov 2014
  
    
    
    
    
    Modifié(e) : Azzi Abdelmalek
      
      
 le 15 Nov 2014
            Say
A = [1 2 3;
     1 4 6;
     7 8 1;
     6 3 1]
The common number in every row is 1. I want to output the result with all other number except the common number, 1. Desired result is
[2 3 4 6 7 8]
repeated numbers are shown once only. As I know, this can be achieved using 'unique(A)'. But I dunno how to get rid of the common number. Thank you all for help!
0 commentaires
Réponse acceptée
  Azzi Abdelmalek
      
      
 le 15 Nov 2014
        
      Modifié(e) : Azzi Abdelmalek
      
      
 le 15 Nov 2014
  
      A = [1 2 3; 1 4 6; 7 8 1; 6 3 1]; 
[ii,jj,kk]=unique(sort(A,2))
setdiff(ii,ii(histc(kk,1:numel(ii))==size(A,1)))
Or
[ii,jj,kk]=unique(sort(A,2))
out=ii(histc(kk,1:numel(ii))<size(A,1))
0 commentaires
Plus de réponses (2)
  Azzi Abdelmalek
      
      
 le 15 Nov 2014
        A = [1 2 3; 1 4 6; 7 8 1; 6 3 1]
B=A(2:end,:);
idx=arrayfun(@(x)  all(any(ismember(B,x),2)),A(1,:))
out=setdiff(unique(B),A(idx))
0 commentaires
  the cyclist
      
      
 le 15 Nov 2014
        Here is a straightforward method:
A = [1 2 3;
     1 4 6;
     7 8 1;
     6 3 1];
common = A(1,:);
for nr = 2:size(A,1)
    common = intersect(common,A(nr,:));
end
result = setdiff(A,common)
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


