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!