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.

7 次查看(过去 30 天)
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

采纳的回答

KSSV
KSSV 2022-10-8
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)
iwant = 4×6
7 10 15 22 23 34 21 32 13 20 5 8 9 14 19 26 17 26 17 26 9 16 11 16

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by