3D Matrix multiplication with vector

前端 未结 4 520
一生所求
一生所求 2020-12-10 05:22

This bothers me a bit:

Suppose you have a matrix with three layers.

Is there a simple way to multiply this matrix with a vector of three elements so that the

4条回答
  •  盖世英雄少女心
    2020-12-10 05:53

    One very terse solution is to reshape vector into a 1-by-1-by-3 matrix and use the function BSXFUN to perform the element-wise multiplication (it will replicate dimensions as needed to match the sizes of the two input arguments):

    newMatrix = bsxfun(@times,matrix,reshape(vector,[1 1 3]));
    

提交回复
热议问题