C = bsxfun(fun, A, B)
| Parameter | Description |
|---|---|
| fun | handle to a binary element-wise function (or a character vector with the function name). Common built-in operations that can be used are: @plus, @minus, @times, @rdivide, @ldivide, @power, @max, @min, @rem, @mod, @hypot, @atan2, @eq, @ne, @lt, @le, @gt, @ge, @and, @or and @xor. Any user-defined binary element-wise function handle is also accepted. |
| A | array (numeric or logical). |
| B | array (numeric or logical). |
| Parameter | Description |
|---|---|
| C | result of applying fun to A and B with singleton expansion. |
bsxfun applies the element-wise binary function fun to arrays A and B, with implicit expansion (singleton dimensions are virtually replicated) so that A and B need not have the same size.
For each dimension, the sizes of A and B must either be equal, or one of them must be 1. A dimension of size 1 is expanded to match the size of the other array. If two corresponding dimensions differ and neither is 1, an error is raised.
The result C has, along each dimension, the larger of the two input sizes. For example, combining an m-by-1 column with a 1-by-n row yields an m-by-n result.
Element-wise operators in Nelson already broadcast singleton dimensions, so A + B is equivalent to bsxfun(@plus, A, B) and is usually the preferred form.
bsxfun(@plus, (1:3)', 1:4)
A = magic(4);
bsxfun(@minus, A, mean(A))
bsxfun(@gt, (1:3)', 1:4)
bsxfun(@(x, y) sqrt(x.^2 + y.^2), (1:3)', 1:4)
bsxfun('times', (1:3)', 1:4)
| Version | Description |
|---|---|
| 2.0.0 | initial version |