table.rowfun
table: B = rowfun (func, A)
table: B = rowfun (func, A, Name, Value, …)
Apply a function to each row of a table.
B = rowfun (func, A) applies the function
handle func to each row of the table A and returns the
results in the table B, which has one row for each row of A.
By default the value of each variable in the row is passed to func
as a separate input argument, and the output variables of B are
named Var1, Var2, and so on.
B = rowfun (func, A, Name, Value,
…) modifies the operation through the following
Name/Value pairs:
'InputVariables''GroupingVariables'GroupCount variable. Rows with a missing value in any
grouping variable are omitted.'OutputVariableNames''NumOutputs''OutputVariableNames' if those are given,
otherwise to 1.'SeparateInputs'true (the default), the value of each
input variable is passed to func as a separate argument. When
false, the values of the row are horizontally concatenated and
passed as a single argument.'ExtractCellContents'true, the contents of cell-valued
variables are extracted before being passed to func. It defaults
to false.'OutputFormat''auto' (the default, equivalent to
'table'), 'table', 'uniform', or 'cell'.
For 'uniform', every call to func must return scalars of
the same type, which are concatenated into an array. For 'cell'
the results are returned in a cell array. The 'uniform' and
'cell' formats return only the results of func.'ErrorHandler'identifier, message,
and index followed by the inputs passed to func.Source Code: table
rowfun applies a function to each row, passing that row's variables as separate arguments — a row-wise map, complementing the column-wise varfun.
Weight = [176; 163; 133]; Height = [71; 69; 64]; T = table (Weight, Height)
T =
3x2 table
Weight Height
______ ______
176 71
163 69
133 64
rowfun (@(w, h) 703 * w / h^2, T, 'OutputVariableNames', {'BMI'})
ans =
3x1 table
BMI
_______
24.5443
24.0683
22.8269