calling a function in another function by changing only few input arguments

조회 수: 2 (최근 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);

채택된 답변

Cedric
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개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by