More About

Diagonal Matrix

A matrix is diagonal if all elements above
and below the main diagonal are zero. Any number of the elements on
the main diagonal can also be zero.

For example, the 4-by-4 identity matrix,

I4=(1000010000100001)

is a diagonal matrix. Diagonal matrices are typically, but not
always, square.

Tips

Use the diag function
to produce diagonal matrices for which isdiag returns
logical 1 (true).

The functions isdiag, istriu,
and istril are special cases of the function isbanded, which can perform all of the
same tests with suitably defined upper and lower bandwidths. For example, isdiag(A)
== isbanded(A,0,0).

Extended Capabilities

C/C++ Code GenerationGenerate C and C++ code using MATLAB® Coder™.

Usage notes and limitations:

Code generation does not support sparse matrix inputs for this
function.