For example if k =0 or number of input arguments ==1
If input argument A is a scalar, y is a vector of length
(A*(A-1)/2)+A containing the linear indexes of the
elements on and above diagonal of a square matrix of order A.
If input argument A is a square matrix of order r (r>1), y
is a vector of length (r*(r-1)/2)+r containing the elements
on and above diagonal of matrix A.
For example if k == 2
If input argument A is a scalar, y is a vector of length
(A*(A-1)/2)+A -A -(A-1) containing the linear indexes of the
elements on and above the 2nd diagonal of a square matrix of
order A.
If input argument A is a square matrix of order r (r>1), y
is a vector of length (r*(r-1)/2)+r -r -(r-1) containing the
elements on and above the 2nd diagonal of a square matrix of
order A.
Remark 1: if the elements on and above diagonal must be extracted
repeatedly, it is convenient to find the linear indexes once
and for all
Remark 2: the linear indices of the upper triangualar part of a
square matrix A of size r can be also obtained with the following
formulas and code:
ind=(1:(r*(r-1)/2))';
j = round(floor(-.5 + .5 * sqrt(1 + 8 * (ind - 1))) + 2);
i = round(j .* (3 - j) / 2 + ind - 1);
y = i + (j - 1).*r; the linear indexes
A1 = A(:);
y = A1(y); the elements above diagonal of matrix A