FUNCTION REFERENCE

spdiags

Sparse matrix from diagonals.

Sparse matrix from diagonals.

Syntax

S = spdiags(B, d, m, n)

Column k of B becomes diagonal d(k) of the m-by-n result (0 is the main diagonal, positive above, negative below). When m >= n, element B(j,k) goes to column j of the result; when m < n, to row j.

Example

full(spdiags(reshape(1:12, 4, 3), [-1 0 1], 5, 4))   % [5 10 0 0; 1 6 11 0; 0 2 7 12; 0 0 3 8; 0 0 0 4]

Example

full(spdiags([1 2 3]', 0, 3, 3))   % diag([1 2 3])

Differences from MATLAB: Only the create form spdiags(B,d,m,n) is supported yet; the extraction and replacement forms give an error.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.