How to find relation between two set?

11 visualizaciones (últimos 30 días)
Sanket Raval
Sanket Raval el 6 de Feb. de 2022
Respondida: Image Analyst el 6 de Feb. de 2022
I have two set of variable:
i=1
c=[1 2 3 4 5 6]
Now How can I find that i is in the c or i is the part of c?
I also want to make decision on that if i is in the c.
  1 comentario
Sanket Raval
Sanket Raval el 6 de Feb. de 2022
i=1;
c=[1 2 3 4 5 6];
M=ismember(c,i);
N=any(M)
I found this solution.
Your suggestions are welcome.

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 6 de Feb. de 2022
Try ismember():
i=3;
c=[1 2 3 4 5 6];
[ia1, ic1] = ismember(i, c)
ia1 = logical
1
ic1 = 3
[ia2, ic2] = ismember(c, i)
ia2 = 1×6 logical array
0 0 1 0 0 0
ic2 = 1×6
0 0 1 0 0 0
Use whichever form gives you the information you need or want.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements 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