A = plus_diag(A, x); % Using [1] below
Adds a vector x onto the diagonal elements of a huge matrix A. In old versions of Matlab, 2*huge memory would temporarily be allocated. Now the memory usage doesn't increase: A is altered in place. This optimization happens automatically when Matlab notices it can be done. The code has to be in a function though, not run from the command-line or a script.[1] http://homepages.inf.ed.ac.uk/imurray2/code/imurray-matlab/p...