In your accumarray calls you're specifying the third input (sz) as an empty array, which tells accumarray basically "you figure out how large the result should be." If you know how large you want it to be, provide that information to accumarray.
locations = [1 2; 2 1];
values = [2; 3];
A = accumarray(locations, values, [])
B = accumarray(locations, values, [3 3])
In the example above, A is 2-by-2. It doesn't need any more rows and columns to contain the values at the coordinates given in the locations matrix. B is 3-by-3, as while the values do technically fit in a 2-by-2 matrix you explicitly asked for the result to be 3-by-3.
Best Answer