cellfun
Apply function to each cell in cell array
Syntax
A = cellfun(func,C)
A = cellfun(func,C1,...,Cn)
A = cellfun(___,南e,Value)
[A1,...,Am] = cellfun(___)
Description
applies the functionA
= cellfun(func
,C
)func
to the contents of each cell of cell arrayC
, one cell at a time.cellfun
then concatenates the outputs fromfunc
into the output arrayA
, so that for thei
th element ofC
,A(i) = func(C{i})
. The input argumentfunc
is a function handle to a function that takes one input argument and returns a scalar. The output fromfunc
can have any data type, so long as objects of that type can be concatenated. The arrayA
and cell arrayC
have the same size.
You cannot specify the order in whichcellfun
calculates the elements ofA
或者依靠他们在任何特定的顺序.
A = cellfun(
appliesfunc
,C1,...,Cn)func
to the contents of the cells ofC1,...,Cn
, so thatA(i) = func(C1{i},...,Cn{i})
. The functionfunc
must taken
input arguments and return a scalar. The cell arraysC1,...,Cn
all must have the same size.
A = cellfun(___,
appliesName,Value
)func
with additional options specified by one or moreName,Value
pair arguments. For example, to return output values in a cell array, specify'UniformOutput',false
. You can returnA
as a cell array whenfunc
returns values that cannot be concatenated into an array. You can useName,Value
pair arguments with the input arguments of either of the previous syntaxes.
[A1,...,Am] = cellfun(___)
returns multiple output arraysA1,...,Am
whenfunc
returnsm
output values.func
can return output arguments that have different data types, but the data type of each output must be the same each timefunc
is called. You can use this syntax with any of the input arguments of the previous syntaxes.
The number of output arguments fromfunc
need not be the same as the number of input arguments specified byC1,...,Cn
.