comparison scripts/sparse/spfun.m @ 11469:c776f063fefe

Overhaul m-script files to use common variable name between code and documentation.
author Rik <octave@nomad.inbox5.com>
date Sun, 09 Jan 2011 12:41:21 -0800
parents a8ce6bdecce5
children fd0a3ac60b0e
comparison
equal deleted inserted replaced
11468:e1edf0ba3bcb 11469:c776f063fefe
16 ## You should have received a copy of the GNU General Public License 16 ## You should have received a copy of the GNU General Public License
17 ## along with Octave; see the file COPYING. If not, see 17 ## along with Octave; see the file COPYING. If not, see
18 ## <http://www.gnu.org/licenses/>. 18 ## <http://www.gnu.org/licenses/>.
19 19
20 ## -*- texinfo -*- 20 ## -*- texinfo -*-
21 ## @deftypefn {Function File} {@var{y} =} spfun (@var{f},@var{x}) 21 ## @deftypefn {Function File} {@var{y} =} spfun (@var{f},@var{S})
22 ## Compute @code{f(@var{x})} for the non-zero values of @var{x}. 22 ## Compute @code{f(@var{S})} for the non-zero values of @var{S}.
23 ## This results in a sparse matrix with the same structure as 23 ## This results in a sparse matrix with the same structure as
24 ## @var{x}. The function @var{f} can be passed as a string, a 24 ## @var{S}. The function @var{f} can be passed as a string, a
25 ## function handle, or an inline function. 25 ## function handle, or an inline function.
26 ## @seealso{arrayfun, cellfun, structfun} 26 ## @seealso{arrayfun, cellfun, structfun}
27 ## @end deftypefn 27 ## @end deftypefn
28 28
29 function t = spfun (f, s) 29 function y = spfun (f, S)
30 30
31 if (nargin != 2) 31 if (nargin != 2)
32 print_usage (); 32 print_usage ();
33 endif 33 endif
34 34
35 [i, j, v] = find (s); 35 [i, j, v] = find (S);
36 [m, n] = size (s); 36 [m, n] = size (S);
37 37
38 if (isa (f, "function_handle") || isa (f, "inline function")) 38 if (isa (f, "function_handle") || isa (f, "inline function"))
39 t = sparse (i, j, f(v), m, n); 39 y = sparse (i, j, f(v), m, n);
40 else 40 else
41 t = sparse(i, j, feval (f, v), m, n); 41 y = sparse(i, j, feval (f, v), m, n);
42 endif 42 endif
43 43
44 endfunction 44 endfunction
45 45
46 %!assert(spfun('exp',[1,2;3,0]),sparse([exp(1),exp(2);exp(3),0])) 46 %!assert(spfun('exp',[1,2;3,0]),sparse([exp(1),exp(2);exp(3),0]))