How to find relation between two set?

조회 수: 10 (최근 30일)
Sanket Raval
Sanket Raval 2022년 2월 6일
답변: Image Analyst 2022년 2월 6일
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
Sanket Raval
Sanket Raval 2022년 2월 6일
i=1;
c=[1 2 3 4 5 6];
M=ismember(c,i);
N=any(M)
I found this solution.
Your suggestions are welcome.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2022년 2월 6일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by