spy

Visualizes the sparsity pattern of a matrix.

Category: Mathematics > Sparse Matrices

Syntax

spy(S)

Plots a dot for every nonzero element of S.

spy(S, LineSpec)

Uses a color and marker given by LineSpec.

Description

The plot has the matrix layout, with row 1 at the top, and shows the number of nonzeros under the axis. It quickly reveals structure: bands, blocks, arrow shapes, and the effect of a reordering such as symrcm on the fill pattern.

Input arguments

S
Sparse or full matrix.
LineSpec
Optional marker specification such as 'r*'.

Example

Pattern of a banded matrix

e = ones(12, 1);
A = spdiags([e e e e e], -2:2, 12, 12);
spy(A)

See also

gplot symrcm nnz sparse