%% Return Sum with Integer Type Output
% Specify an additional argument to the sum function by using an anonymous function for the method input.
% Create a vector of data and a matrix ind that defines groups of the data and 3-D indices into the output.

data = int8(10:15)
ind = [1 1 1; 1 1 1; 1 1 2; 1 1 2; 2 3 1; 2 3 2]

% Sum the data by group in their native integer class int8 by using the 'native' option for the sum function. To do this, specify an anonymous function using @(x) sum(x,'native') for the method input. The result is a 2-by-3-by-2 multidimensional array of type int8.

B = accumarray(ind,data,[],@(x) sum(x,'native'))

% Copyright 2020 The MathWorks, Inc.