calling a function in another function by changing only few input arguments
5 次查看(过去 30 天)
显示 更早的评论
I have written a function function
[ yp,PAC ] = PAgent( c5,c6,c7,rcapa,Aineq5,Bineq5,Aeq5,Beq5,lb,ub,options )
suppose if i have to call this function in another function by changing only the input argument 'rcapa', i.e., other input arguments c5,c6,c7.... will not change, but only 'rcapa' changes, can i write like the following,
PA1 = @(rcapa) PAgent([],[],[],rcapa,[],[],[],[],[],[],[] );
[yp1,PAC1]= PA1(rcapa);
0 个评论
采纳的回答
Cedric
2017-10-17
编辑:Cedric
2017-10-17
If you are in another function where variables with the same names are defined (e.g. because they are arguments of the function), but you want to create a wrapper for PAgent as a function of 1 parameter rcapa that calls another function with the same parameters but with this one updated, do it this way:
function otherFunction( c5,c6,c7,rcapa,Aineq5,Bineq5,Aeq5,Beq5,lb,ub,options )
PA1 = @(rcapa) PAgent( c5,c6,c7,rcapa,Aineq5,Bineq5,Aeq5,Beq5,lb,ub,options ) ;
then you can call PA1 with the specific value of rcapa, but all the other arguments will remain the same as defined by/in otherFunction.
This is like creating an internal function. All variables that are not defined locally come from the nesting/external function. The only internal/local variable in
PA1 = @(rcapa) PAgent( c5,c6,c7,rcapa,Aineq5,Bineq5,Aeq5,Beq5,lb,ub,options ) ;
is rcapa.
0 个评论
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!