Programming |

**Returning a Triangular Portion of a Matrix**

The `tril`

and `triu`

functions return a triangular portion of a matrix, the former returning the piece from the lower left and the latter from the upper right. By default, the main diagonal of the matrix divides these two segments. You can use an alternate diagonal by specifying an offset from the main diagonal as a second input argument:

A = magic(6); B = tril(A, -1) B = 0 0 0 0 0 0 3 0 0 0 0 0 31 9 0 0 0 0 8 28 33 0 0 0 30 5 34 12 0 0 4 36 29 13 18 0

**Concatenating Matrices Diagonally **

You can diagonally concatenate matrices to form a composite matrix using the `blkdiag`

function. See Creating a Block Diagonal Matrix for more information on how this works.

Operating on Diagonal Matrices | Empty Matrices, Scalars, and Vectors |

© 1994-2005 The MathWorks, Inc.