Check if columns of matrix are comprised in another matrix?

4 ビュー (過去 30 日間)
Andrew Poissant
Andrew Poissant 2018 年 7 月 26 日
回答済み: Bob Thompson 2018 年 7 月 26 日
I have a matrix, A, that is 2x25x7. I also have a matrix, B, that is 2x17. I want to check each column in B and see if it is identical to any column in A for each layer in A. How would I do that? I looked at the ismember function but it only has a 'rows' attribute, no 'col' attribute.
  1 件のコメント
Paolo
Paolo 2018 年 7 月 26 日
Can you share a sample of A and B?

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

回答 (1 件)

Bob Thompson
Bob Thompson 2018 年 7 月 26 日
[C, IA, IB] = intersect(A,B,'rows');
This will check each row, and return the identical values in C, index in A, and index in B. In glancing at the documentation I did not see anything about columns (pretty much a literal glance), but you could transpose your data and then check rows.
I'm also not quite sure how this will treat a 3D matrix, so you might have to loop through each layer of A.

カテゴリ

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