extract diagonal blocks of sparse matrix

2 次查看(过去 30 天)
Hi everybody,
I have a large sparse n by n matrix A, and also a index vector idxVec. Elements in idxVec like 2,3, 5, 1, etc, and sum(idxVec) =n. How can I get the diagonal blocks specified in idexVec. i.e., block diagonal matrix like blkdiag(A(1:2,1:2), A(3:5,3:5), A(6:10,6:10), A(11:11, 11:11), ...). where the index is get acording to indVec.

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-5-26
eg
A = randi(1548,11);
k = mat2cell(1:size(A,1),1,[2 3 5 1]);
t = cellfun(@(x)A(x,x),k,'un',0);
out = blkdiag(t{:});

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by