Plot function variables for each iteration in fmincon

조회 수: 7 (최근 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 CenterFile Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by