Is there a way to check each index of a matrix against each index of another smaller matrix?
1 回表示 (過去 30 日間)
古いコメントを表示
Is there a way to check each index of a matrix against each index of another smaller matrix? I am trying to create a code that will check the index of one matrix, A, and compare it to another matrix, B. I want to find a row vector in A where none of the index in that row are equal to any of the index in B. I was thinking of using a for loop and somehow incorporating the find() function, but I am not sure where to start. Any tips would be appreciated.
0 件のコメント
採用された回答
Voss
2022 年 4 月 20 日
% a matrix:
A = magic(5)
% a smaller matrix:
B = [1 15 6; 20 12 21; 25 2 9]
% index(es) of row(s) of A that have no elements in B:
find(~any(ismember(A,B),2))
% breaking that expression down a little bit:
ismember(A,B)
any(ismember(A,B),2)
~any(ismember(A,B),2)
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!