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!! 🙂