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!