function f = spfun(fun,s)
%SPFUN Apply function to nonzero matrix elements.
%   F = SPFUN('fun',S) evaluates fun(s) on the nonzero elements of S.
%   e.g. F = SPFUN('exp',S) has the same sparsity pattern as S
%   (except for underflow), whereas EXP(S) has 1's where S has 0's.

%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   $Revision: 5.5 $  $Date: 1997/11/21 23:44:45 $

[i,j,x] = find(s);
[m,n] = size(s);
f = sparse(i,j,feval(fun,x),m,n);

