I tried to multiply two matrices using bsxfun. Here is a sample code.
a = [0,1]; b = [1,2]; q = bsxfun(@times, a, b);
Once I run this code, I get the output
[0 2]
So I tried the following combinations
q1 = bsxfun(@times, a, b'); q2 = bsxfun(@times, a', b); q3 = bsxfun(@times, a', b');
and all gave me a valid output and none of these generate a multiplication error.
The help says the function uses "singleton expansion" which, I suppose, means it inserts a singleton dimension in either of the two matrices to make the multiplication possible.
Can someone explain what exactly "singleton expansion" means and how is it used in this function?
Best Answer