extract diagonal blocks of sparse matrix
조회 수: 1 (최근 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!