MATLAB: Multiply parts of matrices

matrixmultiplication

Hello everyone – many thanks for taking the time to read this.
Matrix A is 63×63 and Matrix B is 63×7
I want to multiply every 9×9 of Matrix A with every 9×1 of Matrix B.
So the first:
9x9 in matrix A with the first 9x1 in Matrix B
1 2 3 4 5 6 7 8 9 1
1 2 3 4 5 6 7 8 9 2
1 2 3 4 5 6 7 8 9 3
1 2 3 4 5 6 7 8 9 4
1 2 3 4 5 6 7 8 9 5
1 2 3 4 5 6 7 8 9 6
1 2 3 4 5 6 7 8 9 7
1 2 3 4 5 6 7 8 9 8
1 2 3 4 5 6 7 8 9 9
Then the second 9×9 to the right in matrix A with the second 9×1 in matrix B.
I'm currently doing it using cells which is great but need to be able to do it outside of cell format.
What would you recommend?

Best Answer

variant 1
A = randi(100,8,6);
B = randi(50,4,3);
[m n] = size(A);
q = 4;
p = 2;
a1 = reshape(permute(reshape(A,q,m/q,p,[]),[1 3 2 4]),q,p,[]);
out = reshape(sum(bsxfun(@times,a1,reshape(B,1,p,[])),2),m,[]);