splitapply
Split data into groups and apply function
Syntax
Description
To split data into groups and apply a function to the groups, use the
findgroups and splitapply functions
together. For more information about calculations on groups of data, see Calculations on Groups of Data.
Y = splitapply(
splits func,X,G)X into groups specified by G and
applies the function func to each group. Then
splitapply returns Y as an array that
contains the concatenated outputs from func for the groups split
out of X. The input argument G is a vector of
positive integers that specifies the groups to which corresponding elements of
X belong.
The output Y and the group numbers G have
the same ordering.
If any elements of G are NaNs, then
splitapply omits the corresponding values in
X when it splits X into groups.
To create G, first use the findgroups function. Then use
splitapply.
Y = splitapply(
splits variables of table func,T,G)T into groups, applies
func, and returns Y as an array. The
splitapply function treats the variables of
T as vectors, matrices, or cell arrays, depending on the data
types and sizes of the table variables. If T has
N variables, then func must accept
N input arguments.
[Y1,...,YM] = splitapply(___) splits variables
into groups and applies func to each group.
func returns multiple output arguments.
Y1,...,YM contains the concatenated outputs from
func for the groups split out of the input data variables.
func can return output arguments that belong to different
classes, but the class of each output must be the same each time
func is called. You can use this syntax with any of the input
arguments of the previous syntaxes.
The number of output arguments from func need not be the same
as the number of input arguments specified by X1,...,XN.
Examples
Input Arguments
More About
Extended Capabilities
Version History
Introduced in R2015b
