# how to pick a submatrix of a sparse matrix quickly(matlab)

I have a large sparse matrix A and i want to pick the submatrix of it to do block jacobi iterations.

For the blocks, i have get a matrix Q that contains the index of nonzero entries in its Jth column define the nodes of Jth block.

my code is:

for i=1:J
lg=find(Q(level).agg(:,i));
D(i).matrix=inv((sparse(A(lg,lg))));
end
D_inverse=sparse(blkdiag(D(1:J).matrix));


and I found that the operations A(lg,lg) cost much time, because A is sparse format,

Is there any other ways to do this purpose (building D_inverse)quickly and efficently?

Thank you

• is it A(lg, lg) that takes time, or is the inv( )? Maybe you could split the operations up into separate lines and profile them. – Dylan Richard Muir Nov 21 '14 at 14:14
• Also, A(lg, lg) will already be sparse; the call the sparse on line 3 is redundant. – Dylan Richard Muir Nov 21 '14 at 14:15
• Thank you! I have splited the operations into two steps, and it's commonly like that, A(lg,lg) takes much time. – Z. Shen Nov 26 '14 at 15:06
• In that case, I'm not sure there's much you can do. – Dylan Richard Muir Nov 27 '14 at 12:35