Main Content

istriu

Determine if matrix is upper triangular

Description

tf = istriu(A) returns logical 1 (true) if A is an upper triangular matrix. Otherwise, it returns logical 0 (false).

example

Examples

collapse all

Create a 5-by-5 matrix.

A = triu(magic(5))
A = 5×5

    17    24     1     8    15
     0     5     7    14    16
     0     0    13    20    22
     0     0     0    21     3
     0     0     0     0     9

Test if the matrix is upper triangular.

istriu(A)
ans = logical
   1

The matrix is upper triangular because all elements below the main diagonal are zero.

Create a 5-by-5 matrix of zeros. Test if the matrix is upper triangular.

Z = zeros(5);
istriu(Z)
ans = logical
   1

The result is logical 1 (true) because an upper triangular matrix can have any number of zeros on the main diagonal.

Input Arguments

collapse all

Input array. istriu returns logical 0 (false) if A has more than two dimensions.

Data Types: single | double | logical
Complex Number Support: Yes

More About

collapse all

Tips

  • Use the triu function to produce upper triangular matrices for which istriu 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, istriu(A) == isbanded(A,0,size(A,2)).

Extended Capabilities

expand all

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

Version History

Introduced in R2014a

expand all