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

NameDescription
BMatrix whose columns are the diagonals
dVector of diagonal positions (0 = main, positive = above, negative = below)
mNumber of rows
nNumber 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)

See Also