# blkdiag

Block diagonal matrix

## Syntax

``B = blkdiag(A1,...,AN)``

## Description

example

````B = blkdiag(A1,...,AN)` returns the block diagonal matrix created by aligning the input matrices `A1,...,AN` along the diagonal of `B`.```

## Examples

collapse all

Create a block diagonal matrix from three matrices of different sizes.

```A1 = ones(2,2); A2 = 2*ones(3,2); A3 = 3*ones(2,3); B = blkdiag(A1,A2,A3)```
```B = 7×7 1 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 2 2 0 0 0 0 0 2 2 0 0 0 0 0 2 2 0 0 0 0 0 0 0 3 3 3 0 0 0 0 3 3 3 ```

## Input Arguments

collapse all

Input matrices, specified as a comma-separated list of matrices. The matrices can be either square or rectangular and can differ in size.

If any of the input matrices are sparse, then the output block diagonal matrix is also sparse.

collapse all

### Block Diagonal Matrix

A block diagonal matrix is a matrix whose diagonal contains blocks of smaller matrices, in contrast to a regular diagonal matrix with single elements along the diagonal. A block diagonal matrix takes on the following form, where A1, A2,…, AN are each matrices that can differ in size: 