<< Help function for EMD Help function for EMD addtag >>

EMD Toolbox >> EMD Toolbox > Help function for EMD > accumarray

accumarray

Create an array by accumulating the elements of a vector into the positions defined by their subscripts.

Calling Sequence

A = accumarray (subs, val, sz)

Description

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 @var{subs} and the values by @var{vals}. Each row of @var{subs} corresponds to one of the values in @var{vals}.

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

The default action of @code{accumarray} is to sum the elements with the same subscripts. This behavior can be modified by defining the @var{func} 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 associated with them are set to zero. Defining @var{fillval} to some other value allows these values to be defined.

Examples

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]

Authors

<< Help function for EMD Help function for EMD addtag >>