MATLAB: For a loop , to carry out element by element multiplication is bsxfun better than conventional element by element.

bsxfunfastoptimization

for number of iterations
A = A.*B; %A and B both are complex
end
Will the loop be faster if I replace A.*B with bsxfun(@times,A,B) . Why?

Best Answer

Only in the circumstances that you are using R2016b or later and B has a different dimension than A, such as if A is 2d and B is a vector with the same number of rows as A has. Releases before that would return an error message in that situation, but starting R2016b MATLAB would use implicit expansion. Implicit expansion has been timed as no faster than bsxfun and typically a bit slower than bsxfun.
But in the case where the two array are the same size, bsxfun is expected to be slightly slower due to the overhead of testing to determine that regular operations can be used.
Related Question