How to find relation between two set?

8 ビュー (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by