cellfun

Evaluates the function func on the cell array c. Each element is passed into the function individually.

Syntax

R = cellfun(func, input1)

R = cellfun(func, input2, input2)

R = cellfun(..., 'uniformoutput', flag)

Inputs

func
Function to be evaluated.
Type: char | string | handle
input1
Cell array to be operated on.
Type: cell
input2 (optional)
Cell array which contains additional inputs for func.
Type: cell
flag
Uniform output type which specifies the class of R. By default, flag is 1, with R being a matrix. If flag is 0, R will be a cell
Type: integer | log

Outputs

R
Resulting output.

Examples

String cellfun with default options:
a = {1, [1,2;3,4], [1,2,3;4,5,6;7,8,9]};
R = cellfun('det',a)
R = [Matrix] 1 x 3
1.00000e+00  -2.00000e+00  6.66134e-16
Function handle cellfun with default options:
function z=my_func(a)
  z=det(a);
end
a = {1, [1,2;3,4], [1,2,3;4,5,6;7,8,9]};
R = cellfun(@my_func,a)
R = [Matrix] 1 x 3
1.00000e+00  -2.00000e+00  6.66134e-16
cellfun with UniformOutput option:
R = cellfun('sqrt',{2,36,-9,[4,9;16,36],[4i+9,36i-16]},'uniformoutput',0)
R =
{
  [1,1] 1.41421356
  [1,2] 6
  [1,3] 0 + 3i
  [1,4] [Matrix] 2 x 2
  2  3
  4  6 
  [1,5] [Matrix] 1 x 2
  3.06992 + 0.65148i  3.42019 + 5.26286i
}