bsxfun
Apply a binary function with broadcasting.
Syntax
Section titled “Syntax”C = bsxfun(fun, A, B)Description
Section titled “Description”Applies the binary function fun to corresponding elements of A and B, broadcasting along singleton dimensions. fun must be a function handle of the form @(x, y) ... (or a built-in name like @plus, @times).
MathJet’s +, -, .*, etc. operators already broadcast natively, so bsxfun(@plus, A, B) is equivalent to A + B. Provided primarily for compatibility with MATLAB code that predates implicit broadcasting.
Examples
Section titled “Examples”A = [1 2 3];B = [10; 20; 30];bsxfun(@plus, A, B) % 3×3: [11 12 13; 21 22 23; 31 32 33]bsxfun(@times, A, B) % 3×3 elementwise broadcast multiplySee also
Section titled “See also”mtimes— Matrix multiplication (A * B).