Sparse Block Matrix Construction

4 ビュー (過去 30 日間)
Gideon simpson
Gideon simpson 2015 年 5 月 22 日
編集済み: James Tursa 2015 年 5 月 22 日
I want to construct a matrix that looks like
X = [0, A,
B, 0]
Where the A and B blocks are, in themselves, sparse matrices. I already have code for generating the A and B blocks, and I was hoping to reuse that. Is there a way I can then create the X matrix so that it is also sparse?

採用された回答

James Tursa
James Tursa 2015 年 5 月 22 日
編集済み: James Tursa 2015 年 5 月 22 日
[Am,An] = size(A);
[Bm,Bn] = size(B);
X = spalloc(Am+Bm,An+Bn,nnz(A)+nnz(B));
X(Am+1:Am+Bm,1:Bn) = B;
X(1:Am,Bn+1:An+Bn) = A;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSparse Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by