How to find relation between two set?

8 views (last 30 days)
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 Comment
Sanket Raval
Sanket Raval on 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.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 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.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!