I have two 4x4 matrices. I sub-divided these matrices in 4 2x2 matrices each. Now I want to compare these 2x2 matrices.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Vaibav Reddy
le 12 Août 2022
Réponse apportée : Alan Stevens
le 12 Août 2022
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.
0 commentaires
Réponse acceptée
Alan Stevens
le 12 Août 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
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Elementary Math dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!