Documentation |
Construct array with accumulation
A = accumarray(subs,val) returns an array, A, by accumulating elements of vector val using the subscripts in subs. The values in each row of the m-by-n matrix subs define an n-dimensional subscript into the output, A. If subs is a column vector, the value in each row defines a row subscript into the output, which is also a column vector.
The ith row of subs corresponds to the ith element in the vector, val. The function collects all elements of val that have identical subscripts in subs, applies the function @sum, and then stores the result in the location of A corresponding to the subscript. Elements of A that are not referred to by any row of subs contain the value 0.
A = accumarray(subs,val,sz) returns an array, A, with size sz. Specify sz as a vector of positive integers to define the size of the output, or as [] to let the subscripts in subs determine the size of the output. Use sz when subs does not reference trailing rows, columns, or dimensions that you would like to be present in the output.
A = accumarray(subs,val,sz,fun) applies the function fun to each subset of elements in val that have identical subscripts in subs. Specify fun using the @ symbol (e.g., @mean), or as [] to use the default function, @sum.
full | function_handle | histc | sparse | sum