How to compare between two cell array?
25 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mira le
le 11 Déc 2019
Commenté : Stephen23
le 11 Déc 2019
>> W={ [1 2] , [1 3] , [1 4] , [2 3] , [2 4] }
W =
1×5 cell array
[1×2 double] [1×2 double] [1×2 double] [1×2 double] [1×2 double]
>> F={ [1 2] , [1 3] , [1 4] }
F =
1×3 cell array
[1×2 double] [1×2 double] [1×2 double]
I want to compare each value in F if it is exist in W?
0 commentaires
Réponse acceptée
JESUS DAVID ARIZA ROYETH
le 11 Déc 2019
answer=cell2mat(cellfun(@(x) any(cellfun(@(y) isequal(x,y),W)),F,'uni',false))
6 commentaires
Stephen23
le 11 Déc 2019
Simpler using indexing:
>> X = ismember(cat(1,F{:}),cat(1,W{:}),'rows');
>> cat(1,F{X})
ans =
1 2
1 4
>> cat(2,F{X})
ans =
1 2 1 4
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing 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!