Hi, Everyone:
Suppose I have a very large M*N sparse matrix A, where M=K*N, I need to equally split it into K N*N matrices and put all of them on the diagnal of a large matrix,i.e.:
[N*N(1) 0 0 0...0 0 0 ; 0 0 N*N(2) 0 0 ... 0 ; 0 0 . 0 0 ... 0 ; 0 0 0 0 . 0 0 ... 0 ; 0 0 0 0 0 . 0 ... 0 ; 0 0 ... 0 0 0 0 N*N(K)]'
I can't use loop because K is very big, so I tried to use:
B=mat2cell(A,N*ones(K,1),N); C=[blkdiag(B{1:end,1})];
But I found mat2cell is still quite slow when K is very big, is there any other more efficient way to do this?
Many Thanks
Best Answer