splitapply
Split data into groups and apply a function.
📝Syntax
Y = splitapply(func, A, G)
Y = splitapply(func, A1, ..., An, G)
[Y1, ..., Ym] = splitapply(func, ..., G)
📥Input Arguments
Parameter Description
func a function handle applied to each group.
A, A1, ..., An the data to split by group (rows).
G group numbers, typically from findgroups.
📤Output Arguments
Parameter Description
Y the results, with one row per group.
📄Description

Y = splitapply(func, A, G) splits A into groups according to G and applies func to each group, concatenating the results.

💡Examples
G = findgroups([1; 2; 1; 2; 1]);
Y = splitapply(@sum, [10; 20; 30; 40; 50], G)
🔗See Also
findgroupsaccumarray
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub