When the 'subs' values are not in what Mathworks considers as "sorted order", the 'accumarray' algorithm calls for some kind of sorting operation to place 'subs' in sorted order, and it subsequently reorders the 'val' vector accordingly. However, apparently the sorting operation which is used does not necessarily behave in the same way Mathworks' own 'sort' function does with respect to equal entries. For equal entries, matlab's 'sort' operation guarantees that the corresponding sort indices are a sequence of successively increasing integers. That is, if one does
the value for IX is guaranteed to be [3,1,2] and never [3,2,1]. Such is apparently not true for whatever sorting method Mathworks is using with 'accumarray'. Sometimes the index order for equal entries is reversed as apparently happens in their Example 2 in which the indexing is reversed for the two [1,2] equal entries, leading to a sequence of 'val' values of 102,101 instead of the expected 101,102. It would be interesting to find out just what sorting algorithm Mathworks is using in 'accumarray' that it produces such reversals for equal entries.
Best Answer