1
## Copyright (C) 2007, Muthiah Annamalai
3
## Apply function like in LISP. Pass a (row only)cell-array of arguments,
4
## supplied on invoking the function.
6
## This program is free software; you can redistribute it and/or modify
7
## it under the terms of the GNU General Public License as published by
8
## the Free Software Foundation; either version 2 of the License, or
9
## (at your option) any later version.
11
## This program is distributed in the hope that it will be useful,
12
## but WITHOUT ANY WARRANTY; without even the implied warranty of
13
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
## GNU General Public License for more details.
16
## You should have received a copy of the GNU General Public License
17
## along with this program; if not, see <http://www.gnu.org/licenses/>.
1
## Copyright (C) 2007, Muthiah Annamalai <muthiah.annamalai@uta.edu>
3
## This program is free software; you can redistribute it and/or modify it under
4
## the terms of the GNU General Public License as published by the Free Software
5
## Foundation; either version 3 of the License, or (at your option) any later
8
## This program is distributed in the hope that it will be useful, but WITHOUT
9
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13
## You should have received a copy of the GNU General Public License along with
14
## this program; if not, see <http://www.gnu.org/licenses/>.
21
17
## @deftypefn {Loadable Function} {@var{return_value} =} apply (@var{@@function_handle},@var{cell_array_of_args})
26
22
## @var{function_handle}(arg1, arg2, ... ,argn), where the arguments are
27
23
## extracted from each elements of the 1-row cell array @var{cell_array_of_args}.
25
## @emph{warning}: @code{apply} has been deprecated in favor of @code{arrayfun}
26
## and @code{cellfun} for arrays and cells respectively. This function will be
27
## removed from future versions of the 'miscellaneous' package".
29
29
## Apply also works on array of function handles if
30
30
## @var{function_handle} is passed as a cell array of a handles; in this
31
31
## case apply, evaluates each function (using the handle) with the same
56
56
function rval=apply(fun_handle,cell_array)
58
persistent warned = false;
61
warning ("Octave:deprecated-function",
62
"apply has been deprecated, and will be removed in the future. Use `arrayfun' or `cellfun' instead.");
60
67
error("apply(): needs at least 1 argument, see usage");
61
68
elseif( nargin < 2)
62
69
if iscell(fun_handle)
63
70
for idx=1:length(fun_handle)
64
rval(idx)=feval(@feval,fun_handle{idx});
71
rval(idx)=feval(@feval,fun_handle{idx});
67
74
rval=feval(@feval,fun_handle);