Optimise setVal at end of matrix