Plot function variables for each iteration in fmincon

6 Ansichten (letzte 30 Tage)
Suvrat Ramasubramanian
Suvrat Ramasubramanian am 23 Sep. 2017
Kommentiert: Xingwang Yong am 8 Apr. 2021
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.

Akzeptierte Antwort

Matt J
Matt J am 23 Sep. 2017
Bearbeitet: Matt J am 24 Sep. 2017
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 Kommentare
Matt J
Matt J am 25 Sep. 2017
Bearbeitet: Matt J am 25 Sep. 2017
PlotFcns is indeed the more natural thing to use. No idea why it doesn't work.
Xingwang Yong
Xingwang Yong am 8 Apr. 2021
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Problem-Based Optimization Setup finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by