triu - Upper triangular part of matrix

Syntax

U = triu(X)
U = triu(X,k)

Description

U = triu(X) returns the upper triangular part of X.

U = triu(X,k) returns the element on and above the kth 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)

ans = 

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

See Also

diag, tril

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS