Search code examples
matlabmatrixmatrix-multiplication

Matlab - multiply matrix with vector of matrices


I have a matrix of scalars (A):

    1  2  3 
    4  5  6 
    7  8  9 

And 3 other matrices of the same size (100X200), B,C,D.

I want to do the following:

A*[B,C,D] so that the outcome will be [1*B + 2*C + 3*D, 4*B + 5*C + 6*D, 7*B + 8*C + 9*D].

Using normal multiplication * does not work since [B,C,D] obviously isn't of size 3X3. How can it be done correctly?


Solution

    • What you want to do is this giant sparse matrix multiplication

      fig

      where I is the identity matrix, and the above are stacked vectors and matrix where all the rows and columns are appended together.

    • What you should do as mentioned in the comments is to use the .* operator to write

      F = 1.*B + 2.*C + 3.*D
      G = 4.*B + 5.*C + 6.*D
      H = 7.*B + 8.*C + 9.*D