triu
Upper-triangular part of a matrix.
Syntax
Section titled “Syntax”L = triu(X)L = triu(X, k)Description
Section titled “Description”Returns a matrix the same size as X containing only the upper-triangular elements; everything below the main diagonal is zeroed. With the optional k offset, shifts the boundary: positive k removes k superdiagonals; negative k keeps |k| subdiagonals.
Examples
Section titled “Examples”triu(magic(4)) % keep main diagonal and abovetriu(magic(4), 1) % strict upper (zero out main diagonal too)