How to form a diagonal matrix from sub-matrices?

g = ArrayReshape[Range[9], {3, 3}];
m = KroneckerProduct[DiagonalMatrix[{1, 1, 1, 0}], g]
m // MatrixForm

$$ \left( \begin{array}{cccccccccccc} 1 & 2 & 3 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 4 & 5 & 6 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 7 & 8 & 9 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 2 & 3 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 4 & 5 & 6 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 7 & 8 & 9 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 2 & 3 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 4 & 5 & 6 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 7 & 8 & 9 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ \end{array} \right) $$


How about

G = Array[a, {3, 3}];
Format[a[i_, j_]] = Subscript[a, i, j];
B = ArrayFlatten[{{G,0,0,0},{0,G,0,0}, {0,0,G,0},{0,0,0*G}} ]

enter image description here


I am always fond of the outer product in situations like this...

g = Partition[Range[9], 3];
m = ArrayFlatten@Outer[Times, DiagonalMatrix[{1, 1, 1, 0}], g]
m // MatrixForm

Tags:

Matrix