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!