Effacer les filtres
Effacer les filtres

How could I check that how many elements of x is inside y?

2 vues (au cours des 30 derniers jours)
VIJENDRA
VIJENDRA le 23 Sep 2015
Modifié(e) : Stephen23 le 23 Sep 2015
Suppose I have
x = [2,7,8,11];
and
y = [1,2,4,5,7,8,9,12,15,21,27]
How could I check that how many elements of x is inside y?

Réponse acceptée

Stephen23
Stephen23 le 23 Sep 2015
Modifié(e) : Stephen23 le 23 Sep 2015
You can use ismember:
>> x = [2,7,8,11];
>> y = [1,2,4,5,7,8,9,12,15,21,27];
>> ismember(x,y)
ans =
1 1 1 0
>> sum(ismember(x,y))
ans = 3

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by