cellfun

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

Syntax

R = cellfun(func, c)

Inputs

func
Function to be evaluated.
Type: char | string | handle
c
Cell array to be operated on.
Type: cell
Dimension: scalar | vector | matrix

Outputs

R
Resulting output matrix.

Examples

String cellfun with uniform output option:
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 uniform output option:
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 uniform output and cellfun with non-uniform output:
Uniform Output:
a  = [ 1 2 3 ] ;
b = [ 2 3 4 5 ] ;
c = [ 3 4 5 6 7 ] ;
d = { a , b , c } ;
t = cellfun( 'length' , d )

*t = [Matrix] 1 x 3
3  4  5*

Non-Uniform Output:
a  = [ 1 2 3 ] ;
b = [ 2 3 4 5 ] ;
c = [ 3 4 5 6 7 ] ;
d = { a , b , c } ;
t = cellfun( 'cumsum' , d , 'uniformoutput' , false )

*t = 
{
[1,1] [Matrix] 1 x 3
1  3  6
[1,2] [Matrix] 1 x 4
2  5  9  14
[1,3] [Matrix] 1 x 5
3  7  12  18  25
}*