How can I pass extra parameters to an output function in the Optimization Toolbox?
2 ビュー (過去 30 日間)
古いコメントを表示
I'm trying to specify an output function in my optimization options as an anonymous function so as to pass additional parameters to it. My options structure is defined as follows:
options = optimset('outputfcn',@(x)outfun(x,extraArg),'display','iter',...
'Algorithm','active-set');
...
function stop = outfun(x,optimValues,state,extraarg)
...
...
end % nested function
As a result, I get the following error:
??? Error using ==> runfminsearch>@(x)myfunObj(x,k1,k2,k3)
Too many input arguments.
I need to pass additional arguments to an output function using an anonymous function.
採用された回答
MathWorks Support Team
2011 年 1 月 26 日
An output function expects 3 input arguments:
stop = outfun(x, optimValues, state)
Thus, the anonymous function, which is the value of the 'OutputFcn' property in the call to OPTIMSET, should be defined as follows:
options = optimset('outputfcn',@(x,optimValues,state)outfun(x,optimValues,state,extraArg),'display','iter',...
'Algorithm','active-set');
That is, @(x,optimValues,state)outfun(x,optimValues,state,extraArg) instead of @(x)outfun(x,extraArg).
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Problem-Based Optimization Setup についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!