Function Reference
— Function File: accumarray (subs, vals, sz, fun, fillval, issparse)
— Function File: accumarray (csubs, vals, ...)

Create an array by accumulating the elements of a vector into the positions defined by their subscripts. The subscripts are defined by the rows of the matrix subs and the values by vals. Each row of subs corresponds to one of the values in vals.

The size of the matrix will be determined by the subscripts themselves. However, if sz is defined it determines the matrix size. The length of sz must correspond to the number of columns in subs.

The default action of accumarray is to sum the elements with the same subscripts. This behavior can be modified by defining the fun function. This should be a function or function handle that accepts a column vector and returns a scalar. The result of the function should not depend on the order of the subscripts.

The elements of the returned array that have no subscripts assoicated with them are set to zero. Defining fillval to some other value allows these values to be defined.

By default accumarray returns a full matrix. If issparse is logically true, then a sparse matrix is returned instead.

An example of the use of accumarray is:

          accumarray ([1,1,1;2,1,2;2,3,2;2,1,2;2,3,2], 101:105)
           ans(:,:,1) = [101, 0, 0; 0, 0, 0]
             ans(:,:,2) = [0, 0, 0; 206, 0, 208]