## Octave – Gestione matrici – IV – 85 Sempre nella gestione matici, da qui continuo copiando qui.

Built-in Function: `[s, i] = sort (x)`
Built-in Function: `[s, i] = sort (x, dim)`
Built-in Function: `[s, i] = sort (x, mode)`
Built-in Function: `[s, i] = sort (x, dim, mode)`

Return a copy of `x` with the elements arranged in increasing order.
For matrices, sort orders the elements within columns If the optional argument `dim` is given, then the matrix is sorted along the dimension defined by `dim`. The optional argument `mode` defines the order in which the values will be sorted. Valid values of mode are `"ascend"` or `"descend"`.
The `sort` function may also be used to produce a matrix containing the original row indices of the elements in the sorted matrix. For equal elements, the indices are such that equal elements are listed in the order in which they appeared in the original list.
Sorting of complex entries is done first by `magnitude (abs (z))` and for any ties by phase angle (`angle (z)`). Nota: usando `i` mi da errore; non so perché; chiudo la REPL e rilancio, tutto OK `NaN` values are treated as being greater than any other value and are sorted to the end of the list.
The `sort` function may also be used to sort strings and cell arrays of strings, in which case ASCII dictionary order (uppercase ’A’ precedes lowercase ’a’) of the strings is used.
The algorithm used in sort is optimized for the sorting of partially ordered lists.

Function File: `[s, i] = sortrows (A)`
Function File: `[s, i] = sortrows (A, c)`

Sort the rows of the matrix `A` according to the order of the columns specified in `c`.
By default (`c` omitted, or a particular column unspecified in `c`) an ascending sort order is used. However, if elements of `c` are negative then the corresponding column is sorted in descending order. If the elements of `A` are strings then a lexicographical sort is used.
Example: sort by column 2 in descending order, then 3 in ascending order. Built-in Function: `issorted (a)`
Built-in Function: `issorted (a, mode)`
Built-in Function: `issorted (a, "rows", mode)`

Return true if the array is sorted according to mode, which may be either `"ascending"`, `"descending"`, or `"either"`.
By default, mode is `"ascending"`. `NaN`s are treated in the same manner as `sort`.
If the optional argument `"rows"` is supplied, check whether the array is sorted by rows as output by the function `sortrows` (with no options).
This function does not support sparse matrices. Built-in Function: `nth_element (x, n)`
Built-in Function: `nth_element (x, n, dim)`

Select the n-th smallest element of a vector, using the ordering defined by `sort`.
The result is equivalent to `sort(x)(n)`.
`n` can also be a contiguous range, either ascending `l:u` or descending `u:-1:l`, in which case a range of elements is returned.
If `x` is an array, `nth_element` operates along the dimension defined by `dim`, or the first non-singleton dimension if `dim` is not given.
Programming Note: `nth_element` encapsulates the C++ standard library algorithms `nth_element` and `partial_sort`. On average, the complexity of the operation is `O(M*log(K))`, where `M = size (x, dim)` and `K = length (n)`. This function is intended for cases where the ratio K/M is small; otherwise, it may be better to use `sort`. Function File: `tril (A)`
Function File: `tril (A, k)`
Function File: `tril (A, k, pack)`
Function File: `triu (A)`
Function File: `triu (A, k)`
Function File: `triu (A, k, pack)`

Nota perso: “tril” non è una parola esistente; Octave (anzi Matlab) l’ha creata da “triangular + lower”

Return a new matrix formed by extracting the lower (`tril`) or upper (`triu`) triangular part of the matrix `A`, and setting all other elements to zero.
The second argument is optional, and specifies how many diagonals above or below the main diagonal should also be set to zero.
The default value of `k` is zero, so that `triu` and `tril` normally include the main diagonal as part of the result.
If the value of `k` is nonzero integer, the selection of elements starts at an offset of `k` diagonals above or below the main diagonal; above for positive `k` and below for negative `k`.
The absolute value of `k` must not be greater than the number of subdiagonals or superdiagonals. If the option `"pack"` is given as third argument, the extracted elements are not inserted into a matrix, but rather stacked column-wise one above other.

Built-in Function: `v = vec (x)`
Built-in Function: `v = vec (x, dim)`

Return the vector obtained by stacking the columns of the matrix `x` one above the other.
Without `dim` this is equivalent to `x(:)`.
If `dim` is supplied, the dimensions of `v` are set to `dim` with all elements along the last dimension. This is equivalent to `shiftdim (x(:), 1-dim)`. Function File: `vech (x)`
Return the vector obtained by eliminating all superdiagonal elements of the square matrix `x` and stacking the result one column above the other.
This has uses in matrix calculus where the underlying matrix is symmetric and it would be pointless to keep values above the main diagonal. Function File: `prepad (x, l)`
Function File: `prepad (x, l, c)`
Function File: `prepad (x, l, c, dim)`

Prepend the scalar value `c` to the vector `x` until it is of length `l`. If `c` is not given, a value of 0 is used.
If `length (x) > l`, elements from the beginning of `x` are removed until a vector of length `l` is obtained.
If `x` is a matrix, elements are prepended or removed from each row.
If the optional argument `dim` is given, operate along this dimension.
If `dim` is larger than the dimensions of `x`, the result will have `dim` dimensions. Function File: `postpad (x, l)`
Function File: `postpad (x, l, c)`
Function File: `postpad (x, l, c, dim)`

Append the scalar value `c` to the vector `x` until it is of length `l`. If `c` is not given, a value of 0 is used.
If `length (x) > l`, elements from the end of `x` are removed until a vector of length `l` is obtained.
If `x` is a matrix, elements are appended or removed from each row.
If the optional argument `dim` is given, operate along this dimension.
If `dim` is larger than the dimensions of `x`, the result will have `dim` dimensions.

Built-in Function: `M = diag (v)`
Built-in Function: `M = diag (v, k)`
Built-in Function: `M = diag (v, m, n)`
Built-in Function: `v = diag (M)`
Built-in Function: `v = diag (M, k)`

Return a diagonal matrix with vector `v` on diagonal `k`.
The second argument is optional. If it is positive, the vector is placed on the k-th superdiagonal. If it is negative, it is placed on the -k-th subdiagonal. The default value of `k` is 0, and the vector is placed on the main diagonal. The 3-input form returns a diagonal matrix with vector `v` on the main diagonal and the resulting matrix being of size `m` rows x `n` columns.
Given a matrix argument, instead of a vector, diag extracts the k-th diagonal of the matrix.

Function File: `blkdiag (A, B, C, ...)`
Build a block diagonal matrix from `A, B, C, ...`
All arguments must be numeric and either two-dimensional matrices or scalars. If any argument is of type sparse, the output will also be sparse. Mi sembra di essere tornato indietro di 30 anni; e se allora avessi avuto Octave che bello sarebbe stato 😀 Posta un commento o usa questo indirizzo per il trackback.