Programming Previous page   Next Page

Operating on Diagonal Matrices

There are several MATLAB functions that work specifically on diagonal matrices.

Function
Description
blkdiag
Construct a block diagonal matrix from input arguments.
diag
Return a diagonal matrix or the diagonals of a matrix.
trace
Compute the sum of the elements on the main diagonal.
tril
Return the lower triangular part of a matrix.
triu
Return the upper triangular part of a matrix.

Constructing a Matrix from a Diagonal Vector

The diag function has two operations that it can perform. You can use it to generate a diagonal matrix:

You can also use the diag function to scan an existing matrix and return the values found along one of the diagonals:


Previous page  Sorting Row Vectors Returning a Triangular Portion of a Matrix Next page

© 1994-2005 The MathWorks, Inc.