Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
VIJENDRA
VIJENDRA el 23 de Sept. de 2015
Editada: Stephen23 el 23 de Sept. de 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?

Respuesta aceptada

Stephen23
Stephen23 el 23 de Sept. de 2015
Editada: Stephen23 el 23 de Sept. de 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

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by