How to have multiple variable function work with vectors -


i'm having trouble dealing scilab functions ; have output in form of 1x6 vector, , i'd have simple way make work 6 variable function.

v = [1,2,3,4,5,6] ; function z=f(a,b,c,d,e,f) ... endfunction f(v) //returns error 

thank

scilab doesn't have direct analogue of python's fcn(*v) function call interpret entries of v multiple arguments.

if want able call function either fcn(1,2,3,4,5,6) or v = 1:6; fcn(v), you'll need add clause beginning:

function z=fcn(a,b,c,d,e,f)     if argn(2)==1         [a,b,c,d,e,f] = (a(1),a(2),a(3),a(4),a(5),a(6))     end // rest of function z = a+b+c+d+e+f endfunction 

now v=1:6; fcn(v) returns 21, fcn(1,2,3,4,5,6) does.

the condition argn(2)==1 checks if function received 1 parameter instead of expected 6; if case, assumes vector. if vector doesn't have enough elements (6) tuple assignment, error thrown.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -