sprand
Sparse uniform random matrix.
Syntax
Section titled “Syntax”S = sprand(m, n, density)S = sprand(m, n, density, rc)S = sprand(A)Description
Section titled “Description”Returns an m × n sparse matrix of uniform-random values in [0, 1] with approximately density * m * n non-zero entries (density is a fraction in [0, 1]).
With the optional rc, controls the reciprocal of the condition number — used to generate test matrices with a known condition number.
With a single sparse argument, returns a new sparse matrix with the same sparsity pattern as A but uniform-random values where A has non-zeros.
Examples
Section titled “Examples”sprand(100, 100, 0.05) % ~500 non-zero entriessprand(speye(5)) % keep diagonal pattern, replace 1s with random