%  ACCUMARRAY Accumulate vector elements.
%   B = ACCUMARRAY(IND,DATA) sums groups of data by accumulating elements
%   of a vector DATA according to the groups specified in IND. The sum is
%   then computed over each group. Each row of the M-by-N matrix IND
%   represents the group assignment for that row in DATA and an
%   N-dimensional index into the output B. ACCUMARRAY collects all elements
%   of DATA that correspond to identical rows in IND, sums those values,
%   and stores the result in the element of B corresponding to that index.
%   Elements of B that are not referred to by any row of IND contain zero.
%
%   IND must contain positive integers. If IND is a matrix with N>1
%   columns, then B is a N-dimensional array of size MAX(IND,[],1). IND may
%   also be a column vector, and B is then also a column vector of length
%   MAX(IND,[],1).
%
%   IND may also be a cell vector with one or more elements, each a vector
%   of positive integers. All of the vectors must have the same length.
%   In this case, IND is treated as if the vectors formed columns of a
%   matrix.
%
%   DATA must be a numeric, logical, or character vector with the same
%   length as the number of rows in IND. DATA may also be a scalar whose
%   value is repeated for all the rows of IND.
%
%   ACCUMARRAY sums values from DATA using the default behavior of SUM.
%
%   B = ACCUMARRAY(IND,DATA,SZ) creates an array B with size SZ, where SZ
%   is a vector of positive integers. If IND is nonempty with N>1 columns,
%   then SZ must have N elements, where ALL(SZ >= MAX(IND,[],1)). If IND is
%   a nonempty column vector, then SZ must be [M 1] where M >= MAX(IND).
%   Specify SZ as [] for the default behavior.
%
%   B = ACCUMARRAY(IND,DATA,SZ,FUN) applies the function FUN to each group
%   specified by IND. FUN is a function that accepts a column vector and
%   returns a numeric, logical, or char scalar, or a scalar cell. B has the
%   same class as the values returned by FUN. FUN is @SUM by default.
%   Specify FUN as [] for the default behavior.
%
%   Note: If the indices in IND are not sorted, FUN should not depend on
%   the order of the values in its input data.
%
%   B = ACCUMARRAY(IND,DATA,SZ,FUN,FILLVAL) puts the scalar value FILLVAL
%   in elements of B that are not referred to by any row of IND. FILLVAL
%   and the values returned by FUN must have the same class. Specify
%   FILLVAL as [] for the default behavior.
%
%   B = ACCUMARRAY(IND,DATA,SZ,FUN,FILLVAL,ISSPARSE) creates an array B
%   that is sparse if the logical scalar ISSPARSE is true, or full if
%   ISSPARSE is false. B is full by default. FILLVAL must be zero or [] if
%   ISSPARSE is true. DATA and the output of FUN must be double if ISSPARSE
%   is true.
%
%   Examples:
%
%   Create a 4-by-1 vector, summing values for repeated 1-D subscripts:
%      ind = [1; 2; 4; 2; 4];
%      A = accumarray(ind, 101:105)
%
%   Create a 2-by-3-by-2 array, summing values for repeated 3-D subscripts:
%      ind = [1 1 1; 2 1 2; 2 3 2; 2 1 2; 2 3 2];
%      A = accumarray(ind, 101:105)
%
%   Create a 2-by-3-by-2 array, summing values natively:
%      ind = [1 1 1; 2 1 2; 2 3 2; 2 1 2; 2 3 2];
%      A = accumarray(ind, int8(101:105), [], @(x) sum(x,'native'))
%      class(A)
%
%   Create an array using MAX, and fill empty elements with NaN:
%      ind = [1 1; 2 1; 2 3; 2 1; 2 3];
%      A = accumarray(ind, 101:105, [2 4], @max, NaN)
%
%   Create a sparse matrix using PROD:
%      ind = [1 1; 2 1; 2 3; 2 1; 2 3];
%      A = accumarray(ind, 101:105, [2 4], @prod, 0, true)
%
%   Count the number of subscripts for each bin:
%      ind = [1 1; 2 1; 2 3; 2 1; 2 3];
%      A = accumarray(ind, 1, [2 4])
%
%   Create a logical array indicating bins with two or more values:
%      ind = [1 1; 2 1; 2 3; 2 1; 2 3];
%      A = accumarray(ind, 101:105, [2 4], @(x) length(x)>1)
%
%   Group values in a cell array:
%      ind = [1 1; 2 1; 2 3; 2 1; 2 3];
%      A = accumarray(ind, 101:105, [2 4], @(x) {x})
%      A{2}
%
%   See also GROUPSUMMARY, GROUPCOUNTS, HISTCOUNTS, SPARSE.

%   Copyright 1984-2022 The MathWorks, Inc.
%   Built-in function.

