Create block diagonal matrix by slicing blocks from non-square matrix
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Saradhi
am 2 Sep. 2011
Kommentiert: Eesha Andharia
am 29 Mai 2019
I have a large 3nx3 matrix comprised of 'n' 3x3 matrices stacked one after the other like:
A=[A1;A2;...An] (A1, a2, ... An are 3x3 matrices and n is of the order of 5000)
I am trying to reshape this matrix into a block diagonal matrix B that is of size 3nx3n in preparation for solving a system of linear equations. I know how to do this for a small number of matrices by manually providing the matrices as input to the blkdiag() function. However, this strategy is not viable for a large n. I need some input on the following aspects:
- I believe I can utilize loops to obtain the necessary result. Is there a different/more optimized way of going about creating the large block matrix while avoiding loops as much as possible?
- Can I create a list of matrices that can be input to blkdiag()? I tried using cell arrays to store the individual matrices but this does not work.
- Is the above strategy to solve the system flawed? Can you suggest a simpler/better way?
Thank you all in advance, Saradhi
0 Kommentare
Akzeptierte Antwort
Fangjun Jiang
am 3 Sep. 2011
a=magic(3);
n=4;
A=repmat(a,n,1);
B=mat2cell(A,3*ones(1,n),3);
C=blkdiag(B{:})
5 Kommentare
Eesha Andharia
am 29 Mai 2019
Hi,
I amable to block diagonalize a 80 by 80 matrix, but how do i get to see its output? Is it just a file?
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!