how to compare 2 or more cell arrays?
    8 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
Hi, i have 2 cells(cell1 and cell2) of size 628*1 and 244*1 respectively, and i want to compare the elements of cell 1 with the elements of cell 2 and return only the matched ones from cell1 and delete the rests
 cell1{k,1}={' *tcaa-a6-2677*';'tcca-a6-2681';' *tcca-aa-3566*';............};
 %
 cell2{k,1}={'TCCA-A6-2671-11A-01R-1758-07';' *TCCA-A6-2677*-11A-01R-0826-07';'TCCA-AA-3520-11A-01R-0721-07'; 'TCCA-AA-3528-11A-01R-1758-07'; *TCCA-AA-3566*-01A-01R-0125-07';.................}
Hints: i tried strncmpi and length, but because of size issue i get confused about which Command statement is better in my case.
0 commentaires
Réponse acceptée
  Stephen23
      
      
 le 9 Mar 2017
        
      Modifié(e) : Stephen23
      
      
 le 9 Mar 2017
  
      After removing the asterisks, space characters, and fixing the first element of C1, this seems to do the job:
 >> C1 = {'tcca-a6-2677';'tcca-a6-2681';'tcca-aa-3566'};
 >> C2 = {'TCCA-A6-2671-11A-01R-1758-07';'TCCA-A6-2677-11A-01R-0826-07';'TCCA-AA-3520-11A-01R-0721-07';'TCCA-AA-3528-11A-01R-1758-07';'TCCA-AA-3566-01A-01R-0125-07'};
 >> fun = @(s)any(strncmpi(s,C2,numel(s)));
 >> out = C1(cellfun(fun,C1))
 out =
   'tcca-a6-2677'
   'tcca-aa-3566'
8 commentaires
  Bharath Sagar
 le 11 Fév 2020
				Hello,
I have a similar need. I have 2 cells(cell1 and cell2) of size 72*1 and 110*1 respectively, and i want to compare the elements of cell 1 with the elements of cell 2 and return only the matched ones from cell1 and delete the rest.
The above mentioned solution is not working for me.
Can you please help me out with this ?
Voir également
Catégories
				En savoir plus sur Characters and Strings dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




