spCreate#

Purpose#

Creates a sparse matrix from vectors of non-zero values, row indices, and column indices.

Format#

y = spCreate(r, c, val, rinds, cinds)#
Parameters:
  • r (scalar) – rows of output matrix.

  • c (scalar) – columns of output matrix.

  • val (Nx1 vector) – non-zero values.

  • rinds (Nx1 vector) – row indices of corresponding non-zero values.

  • cinds (Nx1 vector) – column indices of corresponding non-zero values.

Returns:

y (RxC sparse matrix) – sparse matrix created from the val.

Examples#

// Declare 'y' to be a sparse matrix

sparse matrix y;

// Create the non-zero values to place in the sparse matrix
val = { 1.7, 2.4, 3.2, 4.5 };

// Set the row and column indices for the location in which
// to place each successive element of 'vals' into the new
// matrix
rinds = { 2, 5, 8, 13 };
cinds = { 4, 1, 9, 5 };

y = spCreate(15, 10, val, rinds, cinds);

This example creates a 15x10 sparse matrix y, containing the following non-zero values:

Non-zero value

Index

1.7

(2,4)

2.4

(5,1)

3.2

(8,9)

4.5

(13,5)

Remarks#

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

See also

Functions packedToSp(), denseToSp(), spEye()