ARRAYFUN Apply a Function To Elements of an Array

Section: Array Generation and Manipulations

Usage

The arrayfun function is used to apply a function handle to each element of an input array (or arrays), and to collect the outputs into an array. The general syntax for its use is
   y = arrayfun(fun, x)

where x is an N-dimensional array. In this case, each element of the output y_i is defined as fun(x_i). You can also supply multiple arguments to arrayfun, provided all of the arguments are the same size

   y = arrayfun(fun, x, z,...)

in which case each output y_i = fun(x_i,z_i,...).

If the function returns multiple outputs, then arrayfun can be called with multiple outputs, in which case each output goes to a separate array output

   [y1,y2,...] = arrayfun(fun, x, z, ...)

The assumption is that the output types for each call to fun is the same across the inputs.

Finally, some hints can be provided to arrayfun using the syntax

   [y1,y2,...] = arrayfun(fun, x, z, ..., 'param', value, 'param', value)

where param and value take on the following possible values: