function ip_plus_diag(X,y) % function ip_plus_diag(X,y) % % Example usage: % ip_plus_diag('X','y'); % Does the same as: % X=plus_diag(X,y); % Or % X=X+diag(y); % for vector y % % Should not be necessary, but older Matlabs don't do plus_diag in place. % In theory it has enough information to know it could in this situation. % Matlab R2007a onwards do do plus_diag in place when called from a function % (not a script or the command-line). % % Inputs: % X string giving name of NxN variable in calling workspace % y string giving name of Nx1, 1xN or 1x1 variable... % Iain Murray, June 2006, updated comments July 2008 evalin('caller',['diagidx=(0:size(',X,',1)-1)*size(',X,',1)',... '+(1:size(',X,',1));',... X,'(diagidx)=',X,'(diagidx)+',y,'(:)',39,';']);