isdiag
Tests whether a matrix is diagonal.
Category: Mathematics > Linear Algebra
Syntax
tf = isdiag(A)
True if all entries off the main diagonal are zero.
Description
The diagonal entries themselves may be anything, including zero, so the zero matrix is diagonal. A rectangular matrix qualifies when everything outside the leading diagonal is zero. An empty matrix is diagonal.
Input arguments
A- Numeric or logical matrix; not necessarily square.
Output arguments
tf- Logical scalar.
Example
Three cases
isdiag(eye(3))
isdiag([1 2; 0 3])
isdiag([])
Output
ans = logical
1
ans = logical
0
ans = logical
1