Plot function variables for each iteration in fmincon

6 ビュー (過去 30 日間)
Suvrat Ramasubramanian
Suvrat Ramasubramanian 2017 年 9 月 23 日
コメント済み: Xingwang Yong 2021 年 4 月 8 日
Hi,
I am trying to plot the variables values calculated for each iteration in fmincon. @optimplotx give histogram plot but i want to plot separately each variable for my function. I am able to plot for each function evaluation, but i want the variable values to be plotted for each iteration just like @optimplotfcn.

採用された回答

Matt J
Matt J 2017 年 9 月 23 日
編集済み: Matt J 2017 年 9 月 24 日
You can specify your own custom PlotFcn. You don't have to use one of the pre-written choices like, @optimplotx.
function stop = myplotfun(x, optimValues, state)
persistent data
if ~nargin % example reset mechanism
data=[];
end
if strcmp(state,'iter')
data=[data,x(:)];
plot(data.');
end
stop=0;
end
  11 件のコメント
Matt J
Matt J 2017 年 9 月 25 日
編集済み: Matt J 2017 年 9 月 25 日
PlotFcns is indeed the more natural thing to use. No idea why it doesn't work.
Xingwang Yong
Xingwang Yong 2021 年 4 月 8 日
It seems the reset mechanism above is made wrong on purpose. For completeness, this is one that works
function stop = myplotfun(x, optimValues, state)
persistent data
if strcmp(state,'init') % example reset mechanism
data=[];
end
if strcmp(state,'iter')
data=[data,x(:)];
plot(data.');
end
stop=0;
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProblem-Based Optimization Setup についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by