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 CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by