rowfun

Applies a function to each row of a table.

Category: Language Fundamentals > Data Types

Syntax

B = rowfun(func, A)

Calls func once per row, passing the variables of that row as separate arguments.

B = rowfun(___, 'InputVariables', vars)

Uses only the listed variables as inputs.

B = rowfun(___, 'OutputVariableNames', names)

Names the output variables.

Description

This is the table counterpart of arrayfun. With @(a, b) a + b and a table that has two variables, the function receives the A and B entries of each row and the results form the output column. By default the output variables are named Var1, Var2, ...; pass 'OutputVariableNames' to choose them.

Input arguments

func
Function handle. It receives one value from each input variable and returns a scalar or a row.
A
Table or timetable.
'InputVariables'
Names or indices of the variables passed to func.

Output arguments

B
Table with one row per row of A and the results as variables.

Example

T = table([1;2;3], [4;5;6], 'VariableNames', {'A','B'});
rowfun(@(a, b) a + b, T, 'OutputVariableNames', 'S')
Output
ans = 3×1 table

    S
    _

    5
    7
    9

Notes

The 'SeparateInputs' option is not applied in MatLivre: func always receives the values of a row as separate arguments.

See also

varfun arrayfun cellfun splitapply groupsummary