next up previous contents
Next: Built In Functions Up: Sparse Matrix Support Previous: SPRANDN Sparse Normal Random   Contents

Subsections

SPY Visualize Sparsity Pattern of a Sparse Matrix

Usage

Plots the sparsity pattern of a sparse matrix. The syntax for its use is

   spy(x)

which uses a default color and symbol. Alternately, you can use

   spy(x,colspec)

where colspec is any valid color and symbol spec accepted by plot.

Example

First, an example of a random sparse matrix.

--> y = sprand(1000,1000,.001)
y = 
  <double>  - size: [999 1000]
	Matrix is sparse with 999 nonzeros
--> spy(y,'ro')

which is shown here

2718

Here is a sparse matrix with a little more structure. First we build a sparse matrix with block diagonal structure, and then use spy to visualize the structure.

--> A = sparse(1000,1000);
--> for i=1:25; A((1:40) + 40*(i-1),(1:40) + 40*(i-1)) = 1; end;
--> spy(A,'gx')
--> hold on
--> y = sprand(A);
--> spy(y,'ro');

with the result shown here

2721


Samit K. Basu 2005-03-16