rbmatlab 0.10.01
general/vecmat/spblkdiag.m
00001 function M = spblkdiag(blocks)
00002 %function M = spblkdiag(blocks)
00003 %
00004 % function generating efficiently a sparse matrix containing
00005 % subblocks blocks(:,:,i) as block i along the diagonal.
00006 % this is 1000 times faster than blkdiag!!!!
00007 %
00008 % Bernard Haasdonk 31.8.2009
00009 
00010 [n,m,k] = size(blocks);
00011 
00012 row_ind = (1:n)'*ones(1,m*k);
00013 row_offs =(ones(n*m,1)*(0:(k-1)))*n;
00014 row_ind = row_ind(:)+row_offs(:);
00015 
00016 col_ind = ones(n,1)*(1:(m*k));
00017 col_ind = col_ind(:);
00018 
00019 M = sparse(row_ind,col_ind,blocks(:));%| \docupdate 
All Classes Namespaces Files Functions Variables