%!demo
%! ## `findgroups` assigns each row an integer group number based on its grouping
%! ## variable(s) — the setup step for a `splitapply` computation.  A second output
%! ## returns a table naming each group.
%!
%! Species = {'setosa'; 'virginica'; 'setosa'; 'virginica'; 'setosa'};
%! Petal = [1.4; 5.1; 1.5; 5.9; 1.3];
%! T = table (Species, Petal)
%! [G, groupNames] = findgroups (T(:, 'Species'));
%! G'
%! groupNames
%!
%! ## The group numbers index into `groupNames`, and feed straight into
%! ## `splitapply` to aggregate `Petal` per species.
%! splitapply (@mean, T(:, 'Petal'), G)
