accumarray
Array accumulation.
Syntax
A = accumarray(indx,vals)
A = accumarray(indx,vals,sz,func)
A = accumarray(indx,vals,sz,func)
A = accumarray(indx,vals,sz,func,fillval)
Inputs
- indx
- The array of indices, with one element specified per row. Repeated rows indicate elements to be accumulated. The dimensions of A are the maximum index in each column, unless sz is used.
- vals
- The values corresponding to the rows of indx.
- sz
- The dimensions of A. The dimensions must be at least as large as specified by indx, but no new dimensions can be introduced. (Default: [])
- func
- The handle for the function that operates on the accumulated elements. Using [] defaults to @sum. The function must take a vector input and return a single value.
- fillval
- The value to be assigned to elements of A that are not specified by indx. (Default: 0)
Outputs
- A
- The accumulated result.
Example
A = accumarray([1,2;2,4;2,1;3,5;2,4], [7,3,4,5,9])
A = [Matrix] 3 x 5
0 7 0 0 0
4 0 0 12 0
0 0 0 0 5