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

10 views (last 30 days)
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.

Accepted Answer

Alan Stevens
Alan Stevens on 12 Aug 2022
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

More Answers (0)

Categories

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

Tags

Community Treasure Hunt

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

Start Hunting!