Skip to content

tril

Lower triangular part of a matrix

tril(X)

  • X should be a matrix, i.e., ndims(X) equal to 2.
  • It returns the lower triangular part of X, i.e., elements below and on the main diagonal of X.
  • If X is a character array, elements above the main diagonal are filled with the white-space character.
  • It returns an empty matrix if X is empty.

tril(X, k)

  • k should be an integer scalar, not equal to NaN or Inf.
  • If k < 0, it returns elements below and on the lower k-th diagonal of X.
  • If k > 0, it returns elements below and on the upper k-th diagonal of X.
  • If k == 0, it returns the same result as tril(X).

Example 1: In the following, tril() extracts the lower triangular part of a character array. The upper part is filled with spaces.

a=['abcd';'efgh';'ijkl';'mnop']
tril(a)
a =
abcd
efgh
ijkl
mnop

ans =
a   
ef  
ijk 
mnop