I have two 4x4 matrices. I sub-divided these matrices in 4 2x2 matrices each. Now I want to compare these 2x2 matrices.

10 ビュー (過去 30 日間)
Problem Explanation:
Matrix 1: Matrix 2:
8 7 6 9 0 1 0 1
11 13 4 21 1 0 1 0
2 69 33 27 0 1 0 1
5 3 1 8 1 0 1 0
I want to compare both these matrices but I want to consider a 2x2 sub matrix and compare.
For example:
8 7 compared with 0 1 ( 1st submatrix of matrix 2)
11 13 1 0
6 9 compared with 0 1 (2nd submatrix of matrix 2)
4 21 1 0
and perform the similar method with the other two blocks.
After I compare them I want to print the value of the first matrix which is matching with '1' of the second matrix.
For example:
8 7 compared with 0 1
11 13 1 0
I want to print '7' and '11' since they're matching with '1' and I want to perform the same thing with the other 3 blocks. How do I do it ? . Can you please provide the code for this. Thank you.

採用された回答

Alan Stevens
Alan Stevens 2022 年 8 月 12 日
Something like this:
M1 = [8 7 6 9; 11 13 4 21; 2 69 33 27; 5 3 1 8];
M2 = [0 1 0 1; 1 0 1 0; 0 1 0 1; 1 0 1 0];
M = M1.*M2;
for i = 1:2:3
for j = 1:2:3
m = M(i:i+1, j:j+1);
disp(m(abs(m)>0))
end
end
11 7 4 9 5 69 1 27

その他の回答 (0 件)

カテゴリ

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by