matrix matching w.r.t row

1 回表示 (過去 30 日間)
sermet OGUTCU
sermet OGUTCU 2016 年 6 月 21 日
編集済み: Stephen23 2016 年 6 月 21 日
matrix_1=
0 0 0 1 2 3
2 0 0 4 5 6
4 0 0 7 8 9
6 0 0 10 11 12
7 59 44 13 14 15
8 59 44 15 16 17
8 0 0 18 19 20
10 0 0 20 21 22
matrix_2=
0 0 0
2 0 0
4 0 0
6 0 0
8 0 0
10 0 0
I need to remove all rows of matrix_1 which don't match matrix_2 rows as follows;
merged_matrix=
0 0 0 1 2 3
2 0 0 4 5 6
4 0 0 7 8 9
6 0 0 10 11 12
8 0 0 18 19 20
10 0 0 20 21 22
[7 59 44;8 59 44]
these parts of the matrix_1 don't matched with the rows of matrix_2. Then they need to be removed as above.

採用された回答

Stephen23
Stephen23 2016 年 6 月 21 日
編集済み: Stephen23 2016 年 6 月 21 日
You can use ismember with the rows option:
>> idx = ismember(matrix_1(:,1:3),matrix_2(:,1:3),'rows');
>> out = matrix_1(idx,:)
out =
0 0 0 1 2 3
2 0 0 4 5 6
4 0 0 7 8 9
6 0 0 10 11 12
8 0 0 18 19 20
10 0 0 20 21 22

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by