[Scilab-users] Applying a matrix or list of function arguments.
Samuel Gougeon
sgougeon at free.fr
Mon Jul 14 18:19:53 CEST 2014
Le 13/07/2014 17:19, Llelan D. a écrit :
> If you have a function "f(arg)" that takes one argument, and either a vector,
> matrix, or list of compatible values, is there a simple syntax or function
> to apply each argument in either the vector, matrix, or list as the argument
> to that function resulting in a vector, matrix, or list holding the result
> for each function call?
Cases of a list vs a vector or matrix are clearly different: elements of
a vector or matrix or hypermatrix are of the same type in such a way
that one could expect to process each of them in the same way; while a
list is an heterogenous container, in such a way that a specific
processing could be expected for each type of element.
In the first case, you might use feval() to vectorize the processing of
a scalarly-built function. In the second case, how could it be possible
to avoid using an explicit select/case loop routing the processing
according to elements types?!
Beside feval(), you shall also look at the varargin and varargout help
pages. If you want to initialize the multi-variable output of a
function, the empty list list() must be used instead of the empty matrix [].
HTH
Regards
Samuel
More information about the users
mailing list