Effacer les filtres
Effacer les filtres

Strcmp for two different Cells

5 vues (au cours des 30 derniers jours)
Simon
Simon le 6 Oct 2016
Commenté : Simon le 6 Oct 2016
Hello,
is it possible to compare two Cell-Variables with different sizes?
Example:
var1 = {'A', 'B', 'C'}
var2 = {'A', 'AA', 'B', 'BB', 'BB' , 'U' , 'V' , 'W' }
strcmp(var1,var2)
Result
>> ans = 1 0 1 0 0 0 0 0
The functions checks one element from var1 is existing in var2.

Réponse acceptée

Guillaume
Guillaume le 6 Oct 2016
Use ismember:
var1 = {'A', 'B', 'C'}
var2 = {'A', 'AA', 'B', 'BB', 'BB' , 'U' , 'V' , 'W'}
ismember(var2, var1)

Plus de réponses (1)

Matthias Walle
Matthias Walle le 6 Oct 2016
Do you mean like this?
strcmp(var1{1},var2) + strcmp(var1{2},var2) + strcmp(var1{3},var2)
and you want to use one single strcmp command?
  1 commentaire
Simon
Simon le 6 Oct 2016
Yes, Guillaume's post shows a solution. Thank you.

Connectez-vous pour commenter.

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!

Translated by