MATLAB Function Reference
  Go to function:
    Search    Help Desk 
spfun    Examples

Apply function to nonzero sparse matrix elements

Syntax

Description

The spfun function selectively applies a function to only the nonzero elements of a sparse matrix, preserving the sparsity pattern of the original matrix (except for underflow).

f = spfun('function',S) evaluates function(S) on the nonzero elements of S. function must be the name of a function, usually defined in an M-file, which can accept a matrix argument, S, and evaluate the function at each element of S.

Remarks

Functions that operate element-by-element, like those in the elfun directory, are the most appropriate functions to use with spfun.

Examples

Given the 4-by-4 sparse diagonal matrix

f = spfun('exp',S) has the same sparsity pattern as S:

whereas exp(S) has 1s where S has 0s.



[ Previous | Help Desk | Next ]