GNU Octave Manual Version 3by John W. Eaton, David Bateman, Søren Hauberg Paperback (6"x9"), 568 pages ISBN 095461206X RRP £24.95 ($39.95) |

### 20.1.3 Sparse Matrix Properties

There are a number of functions that return basic information
concerning sparse matrix objects. The most basic of these is
`issparse`

which identifies whether a particular Octave object is
a sparse matrix.

The function `nnz`

returns the number of non-zero entries in a
sparse matrix, and `nzmax`

returns the amount of storage allocated
to it.

The function `spstats`

returns some basic statistics on the
columns of a sparse matrix, including the number of elements, mean
value and variance of each column.

__Loadable Function:__**issparse***(*`expr`)- Return 1 if the value of the expression
`expr`is a sparse matrix.

__Function File:__**nonzeros***(*`s`)- Returns a vector of the non-zero values of the sparse matrix
`s`.

__Built-in Function:__`scalar`=**nnz***(*`a`)- Returns the number of non zero elements in
`a`.See also sparse

__Built-in Function:__`scalar`=**nzmax***(*`SM`)- Return the amount of storage allocated to the sparse matrix
`SM`. Note that Octave tries to free unused memory at the first opportunity for sparse objects. The values returned by*nzmaz*and*nnz*will typically be the same, although they may differ for user-created sparse objects.See also sparse, spalloc

__Mapping Function:__**spmax***(*`x`,`y`,`dim`)__Mapping Function:__[`w`,`iw`] =**spmax***(*`x`)- For a vector argument, return the maximum value. For a matrix
argument, return the maximum value from each column, as a row
vector, or over the dimension
`dim`if defined. For two matrices (or a matrix and scalar), return the pair-wise maximum. Thus,max (max (

`x`))returns the largest element of

`x`, andmax (2:5, pi) => 3.1416 3.1416 4.0000 5.0000

compares each element of the range

`2:5`

with`pi`

, and returns a row vector of the maximum values.For complex arguments, the magnitude of the elements are used for comparison.

If called with one input and two output arguments,

`max`

also returns the first index of the maximum value(s). Thus,[x, ix] = max ([1, 3, 5, 2, 5]) => x = 5 ix = 3

__Mapping Function:__**spmin***(*`x`,`y`,`dim`)__Mapping Function:__[`w`,`iw`] =**spmin***(*`x`)- For a vector argument, return the minimum value. For a matrix
argument, return the minimum value from each column, as a row
vector, or over the dimension
`dim`if defined. For two matrices (or a matrix and scalar), return the pair-wise minimum. Thus,min (min (

`x`))returns the smallest element of

`x`, andmin (2:5, pi) => 2.0000 3.0000 3.1416 3.1416

compares each element of the range

`2:5`

with`pi`

, and returns a row vector of the minimum values.For complex arguments, the magnitude of the elements are used for comparison.

If called with one input and two output arguments,

`min`

also returns the first index of the minimum value(s). Thus,[x, ix] = min ([1, 3, 0, 2, 5]) => x = 0 ix = 3

__Function File:__[`count`,`mean`,`var`] =**spstats***(*`s`)__Function File:__[`count`,`mean`,`var`] =**spstats***(*`s`,`j`)- Return statistics for the non-zero elements of the sparse matrix
`s`.`count`is the number of non-zeros in each column,`mean`is the mean of the non-zeros in each column, and`var`is the variance of the non-zeros in each column.Called with two input arguments, if

`s`is the data and`j`is the bin number for the data, compute the statistics for each bin. In this case, bins can contain data values of zero, whereas with`spstats (`

the zeros are not included.`s`)

ISBN 095461206X | GNU Octave Manual Version 3 | See the print edition |