MATLAB: Creation of matrix where the submatrices are resultants of smaller matrix multiplication

matrixmatrix arraymatrix manipulation

Let size(A) = [m,m] and size(B) = [n, n] and size(Q) = [mn,k]
I want to create a matrix
[ B*P_1*A' B*P_2*A' ... B*P_k*A'] where P_i = reshape(Q(:,i), [n, m])

Best Answer

m = size(A,1);
n = size(B,1);
P = reshape(Q,n,m,[]);
C = P;
for jj = 1:size(P,3)
C(:,:,jj) = B*P(:,:,jj)*A';
end
out = reshape(C,n,[]);