triu
Upper triangular part of a matrix.
t=triu(a)
t=triu(a,k)
Inputs
a Any matrix.
k An integer.
Outputs
t The upper triangular part of a , or the 'pseudo' upper triangular part as defined below.


Description
The output is of the same size as a . If k is not specified, the output is a copy of the input except that all the elements in the lower triangular part, i.e. the elements of the type t[i,j], i>j are replaced by zero in the output.

If k is specified to be positive, all the elements below the k'th super diagonal are zero in in the output, i.e., the elements of the type t[i,j],i>(j-k) are set to zero.

If k is specified to be negative, all the elements below the (-k)'th sub diagonal are zero in in the output, i.e., the elements of the type t[i,j],i>(j-k) are set to zero.
Example
>>a=[1 2 3 4;5 6 7 8;9 10 11 12]
>>a
          1          2          3          4
          5          6          7          8
          9         10         11         12

>>triu(a)
          1          2          3          4
          0          6          7          8
          0          0         11         12

>>triu(a,1)
          0          2          3          4
          0          0          7          8
          0          0          0         12

>>triu(a,2)
          0          0          3          4
          0          0          0          8
          0          0          0          0

>>triu(a,3)
          0          0          0          4
          0          0          0          0
          0          0          0          0

>>triu(a,4)
          0          0          0          0
          0          0          0          0
          0          0          0          0

>>triu(a,5)
          0          0          0          0
          0          0          0          0
          0          0          0          0

>>triu(a,-1)
          1          2          3          4
          5          6          7          8
          0         10         11         12

>>triu(a,-2)
          1          2          3          4
          5          6          7          8
          9         10         11         12

>>triu(a,-3)
          1          2          3          4
          5          6          7          8
          9         10         11         12