out =
varfun (func, obj)
¶out =
varfun (…, 'OptionName'
, OptionValue, …)
¶Apply function to rows in table and collect outputs.
This applies the function func to the elements of each row of obj’s variables, and collects the concatenated output(s) into the variable(s) of a new table.
func is a function handle. It should take as many inputs as there
are variables in obj. Or, it can take a single input, and you must
specify 'SeparateInputs', false
to have the input variables
concatenated before being passed to func. It may return multiple
argouts, but to capture those past the first one, you must explicitly
specify the 'NumOutputs'
or 'OutputVariableNames'
options.
Supported name/value options:
'OutputVariableNames'
Names of table variables to store combined function output arguments in.
'NumOutputs'
Number of output arguments to call function with. If omitted, defaults to number of items in OutputVariableNames if it is supplied, otherwise defaults to 1.
'SeparateInputs'
If true, input variables are passed as separate input arguments to func. If false, they are concatenated together into a row vector and passed as a single argument. Defaults to true.
'ErrorHandler'
A function to call as a fallback when calling func results in an error. It is passed the caught exception, along with the original inputs passed to func, and it has a “second chance” to compute replacement values for that row. This is useful for converting raised errors to missing-value fill values, or logging warnings.
'ExtractCellContents'
Whether to “pop out” the contents of the elements of cell variables in obj, or to leave them as cells. True/false; default is false. If you specify this option, then obj may not have any multi-column cell-valued variables.
'InputVariables'
If specified, only these variables from obj are used as the function inputs, instead of using all variables.
'GroupingVariables'
Not yet implemented.
'OutputFormat'
The format of the output. May be 'table'
(the default),
'uniform'
, or 'cell'
. If it is 'uniform'
or 'cell'
,
the output variables are returned in multiple output arguments from
'rowfun'
.
Returns a table
whose variables are the collected output arguments
of func if OutputFormat is 'table'
. Otherwise, returns
multiple output arguments of whatever type func returned (if
OutputFormat is 'uniform'
) or cells (if OutputFormat
is 'cell'
).