triu

Purpose

Upper triangular part of a matrix.

Synopsis

u = triu(X)
u = triu(X,k)

Description

triu(X) is the upper triangular part of X.

triu(X,k) is the element on and above the k-th diagonal of X. k = 0 is the main diagonal, k > 0 is above the main diagonal, and k < 0 is below the main diagonal.

Examples

triu(ones(4,4),-1) is

    1    1    1    1
    1    1    1    1
    0    1    1    1
    0    0    1    1

See Also

diag, tril

(c) Copyright 1994 by The MathWorks, Inc.