spdiag - sparse diagonal matrix Copyright(c) 2009 Ryota Tomioka This software is distributed under the MIT license. See license.txt
0001 % spdiag - sparse diagonal matrix 0002 % 0003 % Copyright(c) 2009 Ryota Tomioka 0004 % This software is distributed under the MIT license. See license.txt 0005 0006 function D = spdiag(d) 0007 0008 if isempty(d) 0009 D = []; 0010 return; 0011 end 0012 0013 if size(d,1)<size(d,2) 0014 d = d'; 0015 end 0016 0017 D = spdiags(d,0,size(d,1),size(d,1));