A generalization of the function 'diag'
[A, c] = moc_spdiags (v, c, m, n)
A generalization of the function 'diag'. Called with a single input argument, the non-zero diagonals C of A are extracted. With two arguments the diagonals to extract are given by the vector C.
The other two forms of 'spdiags' modify the input matrix by replacing the diagonals. They use the columns of V to replace the columns represented by the vector C. If the sparse matrix A is defined then the diagonals of this matrix are replaced. Otherwise a matrix of M by N is created with the diagonals given by V.
Negative values of C represent diagonals below the main diagonal, and positive values of C diagonals above the main diagonal.
moc_spdiags (matrix (1:12, 4, 3), [-1 0 1], 5, 4) | ![]() | ![]() |