How can I find a vector in a matrix without using cycles?

1 回表示 (過去 30 日間)
Pedro Guevara
Pedro Guevara 2019 年 5 月 22 日
コメント済み: Star Strider 2019 年 5 月 23 日
Good afternoon. The reason for my message is to ask for help with this problem. Let's say I have a matrix "called A" with 2 columns and -n- number of rows, and I need to look for a vector "B" (which is 1 row and 2 columns) within all the rows that make up "A". You must find the vector in a way that recognizes in a sense or in the opposite sense, then I show an example to better understand what I say.
A =
1 2
3 4
5 3
3 1
6 4
4 2
B=
4 6 -------------------> The vector B can also be inverted (6 4).
The result I expect to be told in which row is the vector "B" inside the matrix "A". for the example above I would expect the answer to be row 5
Thank you very much for your help.

採用された回答

Star Strider
Star Strider 2019 年 5 月 22 日
Try this:
A = [1 2
3 4
5 3
3 1
6 4
4 2];
B = [4 6];
Lidx = ismember(sort(A,2),sort(B,2),'rows')
rowNumber = find(Lidx)
producing:
Lidx =
6×1 logical array
0
0
0
0
1
0
rowNumber =
5
  4 件のコメント
Pedro Guevara
Pedro Guevara 2019 年 5 月 22 日
Works perfect companion, thank you very much for your huge help. :)
Star Strider
Star Strider 2019 年 5 月 23 日
Again, as always, my pleasure.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by