Dividing a big matrix into small matrices(or Multiply a portion of a matrix to another) to multiply it with a small matrix and after that re add them into the same position.
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Syed Yasir Azeem
le 8 Oct 2022
Commenté : Syed Yasir Azeem
le 9 Oct 2022
I have a matrix A(400x400) and B(2x2). I want to divide matrix 'A' into 2x2 matrices and multply it with matrix B. Later on Recombine all the matrices from the output into the same locations from where I separated from A.
Example
A = 1 2 3 4 5 6 . . . . B = 1 2
6 5 4 3 2 1 . . . . 3 4
3 2 1 6 5 4 . . . .
5 4 6 1 2 3 . . . .
.
.
I simple want 1 2 ; 6 5 from A to be multiplied with B and restored in the same position and then multiply 3 4 ; 4 3 with B and so on. I am a beginner. Thank you very much
0 commentaires
Réponse acceptée
KSSV
le 8 Oct 2022
A = [1 2 3 4 5 6 ;
6 5 4 3 2 1 ;
3 2 1 6 5 4 ;
5 4 6 1 2 3] ;
B = [1 2 ; 3 4] ;
[m,n] = size(A);
k = [2 2];
C = mat2cell(A,k(1)*ones(m/k(1),1),k(2)*ones(n/k(2),1)) ;
[m,n] = size(C) ;
D = cell(m,n) ;
for i = 1:m
for j = 1:n
D{i,j} = C{i,j}*B ;
end
end
iwant = cell2mat(D)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrices and Arrays 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!