Borrar filtros
Borrar filtros

Finding certain numbers in vectors

1 visualización (últimos 30 días)
Sebastian Daneli
Sebastian Daneli el 23 de Ag. de 2021
Comentada: Wan Ji el 23 de Ag. de 2021
Lets say that I have these vectors
v1=[2 4 1 4]
v2=[1 3 3 4]
v3=[2 6 9 5]
and I wan't to find all the vectors that have any of these numbers
nmbr=[2 5 9]
which whould give med v1 and v3 How would i solve this?

Respuesta aceptada

Wan Ji
Wan Ji el 23 de Ag. de 2021
Editada: Wan Ji el 23 de Ag. de 2021
any(ismember(v1, nmbr))
any(ismember(v2, nmbr))
any(ismember(v3, nmbr))
If true, then the vector has any of these numbers [2 5 9]
  3 comentarios
Sebastian Daneli
Sebastian Daneli el 23 de Ag. de 2021
Thank you
Wan Ji
Wan Ji el 23 de Ag. de 2021
You can also do by combining v1,v2,and v3
v1=[2 4 1 4];
v2=[1 3 3 4];
v3=[2 6 9 5];
V = [v1', v2', v3']; % each column represents a vector
nmbr=[2 5 9];
p = ismember(V,nmbr);
result = find(any(p))
The answer is
result =
1 3
So v1 and v3 are satisfied

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Multidimensional 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