%% Specify Group Bins
% Group data according to specified bins.
% Create a timetable containing sales information for days within a single month.

TimeStamps = datetime([2017 3 4; 2017 3 2; 2017 3 15; 2017 3 10;...
                       2017 3 14; 2017 3 31; 2017 3 25;...
                       2017 3 29; 2017 3 21; 2017 3 18]);
Profit = [2032 3071 1185 2587 1998 2899 3112 909 2619 3085]';
TotalItemsSold = [14 13 8 5 10 16 8 6 7 11]';
TT = timetable(TimeStamps,Profit,TotalItemsSold)

% Compute the mean profit grouped by the total items sold, binning the groups into intervals of item numbers.

format shorte
G = groupsummary(TT,'TotalItemsSold',[0 4 8 12 16],'mean','Profit')

% Compute the mean profit grouped by day of the week.

G = groupsummary(TT,'TimeStamps','dayname','mean','Profit')

% Copyright 2012 The MathWorks, Inc.