[Scilab-users] Applying a matrix or list of function arguments.

Llelan D. LlelanD at TheSnakePitDev.com
Sun Jul 13 17:19:12 CEST 2014


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?

Or can this only be done in a function with a for loop (column vector
version):
function result = handleFArgs(args)
    result = []
    for iArg = 1:size(args, 1)
        result($ + 1) = f(args(iArg))
    end
endfunction

If there is, is it the same for each of a vector, matrix, or list of
arguments? Can it also be done for a function requiring multiple arguments.

One possible example is to gather all of the directory names in the current
directory and then apply that vector to a function that takes a directory
name, performs a "genlib()" with any other error handling or additional
tasks, and returns the compiled and loaded library value resulting in a
vector of libraries, one for each directory in the original vector.
function library = genLoadLib(dirName)
    <generate, load, and return the library in the named directory>
endfunction

files = dir()
dirs = files.name(files.isdir)
libraries = <apply the dirs vector of arguments to the genLoadLib function
               creating a column vector of libraries>

Any assistance with this would be greatly appreciated.




--
View this message in context: http://mailinglists.scilab.org/Applying-a-matrix-or-list-of-function-arguments-tp4030900.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.



More information about the users mailing list