accumarray
Construct array by accumulation.
📝Syntax
A = accumarray(subs, val)
A = accumarray(subs, val, sz)
A = accumarray(subs, val, sz, fun)
A = accumarray(subs, val, sz, fun, fillval)
📥Input Arguments
Parameter Description
subs subscripts: column vector or matrix of positive integers.
val values to accumulate: column vector or scalar.
sz size of the output: row vector or [].
fun accumulation function: function handle (default @sum).
fillval value for empty positions (default 0).
📤Output Arguments
Parameter Description
A accumulated array.
📄Description

accumarray(subs, val) groups the elements of val by the subscripts in subs and applies @sum to each group.

Each row of subs is the position in the output where the corresponding value of val is accumulated.

fun replaces the default sum, and fillval sets the value of positions that receive no contribution.

💡Examples
accumarray([1;2;1;3], [10;20;30;40])
accumarray([1;1;2], [3;5;7], [], @max)
🔗See Also
sumunique
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub