bsxfun implementation in matrix multiplication

前端 未结 5 571
孤城傲影
孤城傲影 2020-11-28 14:36

As always trying to learn more from you, I was hoping I could receive some help with the following code.

I need to accomplish the following:

1) I have a vect

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 15:15

    Send x to the third dimension, so that singleton expansion would come into effect when bsxfun is used for multiplication with A, extending the product result to the third dimension. Then, perform the bsxfun multiplication -

    val = bsxfun(@times,A,permute(x,[3 1 2])) 
    

    Now, val is a 3D matrix and the desired output is expected to be a 2D matrix concatenated along the columns through the third dimension. This is achieved below -

    out = reshape(permute(val,[1 3 2]),size(val,1)*size(val,3),[])
    

    Hope that made sense! Spread the bsxfun word around! woo!! :)

提交回复
热议问题