cellfun
Apply a function to each cell in a cell array.
Syntax
Section titled “Syntax”B = cellfun(fun, C)B = cellfun(fun, C1, C2, ...)Description
Section titled “Description”Applies fun (a function handle, function pointer, or string function name) to each cell in C, returning the results in an array. With multiple cell-array inputs, applies fun to corresponding cells (the cell arrays must have the same shape).
By default, the result is a numeric array — each cell’s output must be a scalar. For non-scalar outputs, MATLAB’s 'UniformOutput', false flag would return a cell of results; this flag form is not yet supported in MathJet.
Examples
Section titled “Examples”cellfun(@length, {'foo', 'longer', 'x'}) % [3 6 1]cellfun(@(x) x.^2, {1, 2, 3}) % [1 4 9]