Find if two elements are in a row of a matrix

1 回表示 (過去 30 日間)
AI-CHI Chang
AI-CHI Chang 2022 年 3 月 6 日
コメント済み: AI-CHI Chang 2022 年 3 月 6 日
I want to find two elements in A are also in B,and I would like to know B's index.
So the answer is 1 2 4 5 in B.
A=[1,3,7]
B=[1 8 3;
1 2 3;
3 4 5;
1 7 9
2 1 3];
This is what I tried.But clearly,it's not smart
find(B(:,1)==A(1,1)&B(:,2)==A(1,2))
find(B(:,1)==A(1,1)&B(:,3)==A(1,2))
find(B(:,2)==A(1,1)&B(:,3)==A(1,2))
(I can sort them and use ismember but it's still not intuitive. Any other function?)
  2 件のコメント
Matt J
Matt J 2022 年 3 月 6 日
So the answer is 1 2 4 5 in B.
Why is that the answer?
AI-CHI Chang
AI-CHI Chang 2022 年 3 月 6 日
Sorry not clear. I just put on part of my solution. It's because B's 1 2 4 5 row have two of elements in A

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2022 年 3 月 6 日
編集済み: Stephen23 2022 年 3 月 6 日
A = [1,3,7];
B = [1,8,3;1,2,3;3,4,5;1,7,9;2,1,3];
V = find(sum(ismember(B,A),2)==2)
V = 4×1
1 2 4 5
  1 件のコメント
AI-CHI Chang
AI-CHI Chang 2022 年 3 月 6 日
It is really helpful !! Thanks~

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by