Function Reference
— Loadable Function: cellfun (name, c)
— Loadable Function: cellfun ("size", c, k)
— Loadable Function: cellfun ("isclass", c, class)
— Loadable Function: cellfun (func, c)
— Loadable Function: cellfun (func, c, d)
— Loadable Function: [a, b] = cellfun (...)
— Loadable Function: cellfun (..., 'ErrorHandler', errfunc)
— Loadable Function: cellfun (..., 'UniformOutput', val)

Evaluate the function named name on the elements of the cell array c. Elements in c are passed on to the named function individually. The function name can be one of the functions

isempty
Return 1 for empty elements.
islogical
Return 1 for logical elements.
isreal
Return 1 for real elements.
length
Return a vector of the lengths of cell elements.
ndims
Return the number of dimensions of each element.
prodofsize
Return the product of dimensions of each element.
size
Return the size along the k-th dimension.
isclass
Return 1 for elements of class.

Additionally, cellfun accepts an arbitrary function func in the form of an inline function, function handle, or the name of a function (in a character string). In the case of a character string argument, the function must accept a single argument named x, and it must return a string value. The function can take one or more arguments, with the inputs args given by c, d, etc. Equally the function can return one or more output arguments. For example

          cellfun (@atan2, {1, 0}, {0, 1})
          ans = [1.57080   0.00000]

Note that the default output argument is an array of the same size as the input arguments.

If the param 'UniformOutput' is set to true (the default), then the function must return either a single element which will be concatenated into the return value. If 'UniformOutput is false, the outputs are concatenated in a cell array. For example

          cellfun ("tolower(x)", {"Foo", "Bar", "FooBar"},
                  "UniformOutput",false)
           ans = {"foo", "bar", "foobar"}

Given the parameter 'ErrorHandler', then errfunc defines a function to call in case func generates an error. The form of the function is

          function [...] = errfunc (s, ...)

where there is an additional input argument to errfunc relative to func, given by s. This is a structure with the elements 'identifier', 'message' and 'index', giving respectively the error identifier, the error message, and the index into the input arguments of the element that caused the error. For example

          function y = foo (s, x), y = NaN; endfunction
          cellfun (@factorial, {-1,2},'ErrorHandler',@foo)
           ans = [NaN 2]