Sparse Block Matrix Construction
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gideon simpson
am 22 Mai 2015
Bearbeitet: James Tursa
am 22 Mai 2015
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?
0 Kommentare
Akzeptierte Antwort
James Tursa
am 22 Mai 2015
Bearbeitet: James Tursa
am 22 Mai 2015
[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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!