Back to Sparse Matrices
spdiags
Sparse matrix formed from diagonals
Syntax
S = spdiags(B, d, m, n)
Description
Creates a sparse m-by-n matrix by placing the columns of B along the diagonals specified by d. Each column of B is placed along the corresponding diagonal in d.
Parameters
| Name | Description |
|---|---|
| B | Matrix whose columns are the diagonals |
| d | Vector of diagonal positions (0 = main, positive = above, negative = below) |
| m | Number of rows |
| n | Number of columns |
Returns
Sparse matrix with specified diagonals
Examples
Try It
>> e = ones(5,1); S = spdiags([-e 2*e -e], [-1 0 1], 5, 5)