spOnes

Purpose

Generates a sparse matrix containing only ones and zeros

Format

y = spOnes(r, c, rinds, cinds)
Parameters:
  • r (scalar) – rows of output matrix.
  • c (scalar) – columns of output matrix.
  • rinds (Nx1 vector) – row indices of ones.
  • cinds (Nx1 vector) – column indices of ones.
Returns:

y (RxC sparse matrix) – ones matrix.

Examples

// declare sparse matrix
sparse matrix y;

// Set row indices and column indices
rinds = { 1, 3, 5 };
cinds = { 2, 1, 3 };

// Create a 5x4 sparse matrix with ones at the intersection
// of the 'rind' and 'cind'
y = spOnes(5, 4, rinds, cinds);

The resulting y is equal to:

0  1  0  0
0  0  0  0
1  0  0  0
0  0  0  0
0  0  1  0

Remarks

Since sparse matrices are strongly typed in GAUSS, y must be defined as a sparse matrix before the call to spOnes().

See also

Functions spCreate(), spEye(), spZeros(), denseToSp()