How to creat an array (k,1) of ordered pairs fro an array (k,2)?

1 回表示 (過去 30 日間)
JazzMusic
JazzMusic 2016 年 11 月 27 日
コメント済み: Star Strider 2016 年 11 月 28 日
For example I have: [1 3; 2 4; 2 5; 3 3] and would like to have: [(1,3);(2,4);(2,5);(3,3)]
I actually need to take two arrays (k,2) and count how many pairs are the same. for example if I have: A = [1 3; 2 4; 2 5; 3 5] and B = [2 3; 2 1; 2 4; 3 5] I want the answer to be 2. Since as a sets of 4 ordered pairs (each), the intersection of A and B contains two elements.
Thanks!

採用された回答

Star Strider
Star Strider 2016 年 11 月 27 日
I believe this is what you want:
A = [1 3; 2 4; 2 5; 3 5];
B = [2 3; 2 1; 2 4; 3 5];
[AB,idx] = ismember(A,B,'rows');
Out = sum(AB)
Out =
2
Note If your arrays are not integers, you will need to use the ismembertol function instead.
  2 件のコメント
JazzMusic
JazzMusic 2016 年 11 月 28 日
Exactly what I needed. Thanks!!
Star Strider
Star Strider 2016 年 11 月 28 日
My pleasure!

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

その他の回答 (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