Apply element-by-element binary operation to two arrays with singleton expansion enabled

`C = bsxfun(fun,A,B)`

`C = bsxfun(fun,A,B)`

applies
the element-by-element binary operation specified by the function
handle `fun`

to arrays `A`

and `B`

,
with singleton expansion enabled. `fun`

can be one
of the following built-in functions:

| Plus |

| Minus |

| Array multiply |

| Right array divide |

| Left array divide |

| Array power |

| Binary maximum |

| Binary minimum |

| Remainder after division |

| Modulus after division |

| Four-quadrant inverse tangent; result in radians |

| Four-quadrant inverse tangent; result in degrees |

| Square root of sum of squares |

| Equal |

| Not equal |

| Less than |

| Less than or equal to |

| Greater than |

| Greater than or equal to |

| Element-wise logical AND |

| Element-wise logical OR |

| Logical exclusive OR |

`fun`

can also be a handle to any binary element-wise
function not listed above. A binary element-wise function of the form ```
C
= fun(A,B)
```

accepts arrays `A`

and `B`

of
arbitrary, but equal size and returns output of the same size. Each
element in the output array `C`

is the result of
an operation on the corresponding elements of `A`

and `B`

only. `fun`

must
also support scalar expansion, such that if `A`

or `B`

is
a scalar, `C`

is the result of applying the scalar
to every element in the other input array.

The corresponding dimensions of `A`

and `B`

must
be equal to each other or equal to one. Whenever a dimension of `A`

or `B`

is
singleton (equal to one), `bsxfun`

virtually replicates
the array along that dimension to match the other array. In the case
where a dimension of `A`

or `B`

is
singleton, and the corresponding dimension in the other array is zero, `bsxfun`

virtually
diminishes the singleton dimension to zero.

The size of the output array `C`

is equal to:`max(size(A),size(B)).*(size(A)>0 & size(B)>0)`

.

Was this topic helpful?