blkdiag

Block diagonal matrix built from the given matrices.

Category: Language Fundamentals > Matrices and Arrays

Syntax

B = blkdiag(A1, A2, ..., An)

Places the inputs along the diagonal and fills the rest with zeros.

Description

Each input becomes one block, placed so that blocks do not overlap and touch only at corners. The first block sits at the top left and the last at the bottom right. This is the usual way to assemble a system matrix from independent subsystems.

Input arguments

A1, ..., An
Numeric matrices, vectors or scalars; they need not be square or the same size.

Output arguments

B
Matrix with as many rows as the inputs have in total and as many columns as they have in total.

Example

blkdiag([1 2], 3, [4 5; 6 7])
Output
ans = 4×5

     1     2     0     0     0
     0     0     3     0     0
     0     0     0     4     5
     0     0     0     6     7

See also

diag cat horzcat vertcat kron