How to find relation between two set?

10 Ansichten (letzte 30 Tage)
Sanket Raval
Sanket Raval am 6 Feb. 2022
Beantwortet: Image Analyst am 6 Feb. 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 Kommentar
Sanket Raval
Sanket Raval am 6 Feb. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 6 Feb. 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.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by