How to quickly obtain the row indices in the original matrix A for a sub-matrix B?

4 ビュー (過去 30 日間)
Dear All,
I have an original matrix A and a sub-matrix which is formed by selected rows from A. Now given A and B, how can I find out the row indices of B in A?
For example,
A = [
0 0 1 0 -1
2 -1 0 0 0
-1 0 -1 0 0
0 0 3 -1 -1
0 0 -1 1 0
0 0 -1 0 1
];
B = [
0 0 1 0 -1
0 0 3 -1 -1
0 0 -1 1 0
0 0 -1 0 1
];
The indices should be ind = [1 4 5 6].
Thanks a lot.
Benson

採用された回答

Stephen23
Stephen23 2021 年 2 月 2 日
[~,Y] = ismember(B,A,'rows')
Y = 4×1
1 4 5 6
  1 件のコメント
Benson Gou
Benson Gou 2021 年 2 月 3 日
Hi, Stephen,
Thanks a lot for your great help. It works very well.
Benson

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOceanography and Hydrology についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by