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.
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!