Skip to content

cellfun

Apply a function to each cell in a cell array.

B = cellfun(fun, C)
B = cellfun(fun, C1, C2, ...)

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.

cellfun(@length, {'foo', 'longer', 'x'}) % [3 6 1]
cellfun(@(x) x.^2, {1, 2, 3}) % [1 4 9]
  • bsxfun — Apply a binary function with broadcasting.
  • cell — Information about formatting, location, or contents of a cell.