Custom Plot Functions in Optimization Toolbox
1 次查看(过去 30 天)
显示 更早的评论
I want to modify the the psplotbestf.m custom plot function, but I can’t seem to get it to work …
As soon as change ANY figure or axes properties other than ‘tag’, the psplotbestf.m stops working.
stop = false;
switch flag
case 'init'
h_OptRsltFig = gcf;
set(h_OptRsltFig,'Tag','OptRsltFig');
h_OptRsltAx = gca;
% set(h_OptRsltAx,'Position',[.1 .1 .6 .8]);
set(h_OptRsltAx,'Tag','OptRsltAx');
h_OptRsltPlt = plot(optimvalues.iteration,optimvalues.fval, '.b');
set(h_OptRsltPlt,'Tag','OptRsltPlt');
xlabel('Iteration','interp','none');
ylabel('Function value','interp','none')
case 'iter'
h_OptRsltFig = findobj('Tag','OptRsltFig');
h_OptRsltAx = findobj(get(h_OptRsltFig,'Children'),'Tag','OptRsltAx');
h_OptRsltPlt = findobj(get(h_OptRsltAx,'Children'),'Tag','OptRsltPlt');
newX = [get(h_OptRsltPlt,'Xdata') optimvalues.iteration];
newY = [get(h_OptRsltPlt,'Ydata') optimvalues.fval];
set(h_OptRsltPlt,'Xdata',newX, 'Ydata',newY);
% set(get(h_OptRsltFig,'Title'),'String',['Best Function Value: ',num2str(optimvalues.fval)]);
end
this codes works fine, BUT if I uncomment the set position line, the code doesn’t work. In the case ‘iter’ section, the findobj for the Axes and Plot with the tag fails to find anything, and returns a zero.
So, it seems that setting the “position” property somehow erases the tag property, or otherwise makes the findobj command not work.
Just to see what was going on, I tried changing ‘name’, ‘title’, and a few other properties as well. If I try to set anything other than ‘tag’, the code fails. It puts up the first point (i.e. the init case runs), but doesn’t add any later points, (i.e. the iter case fails to run properly).
Thanks for any help you can offer.
Steve Clarke
0 个评论
回答(1 个)
Alan Weiss
2012-2-1
This is a function specifically designed for patternsearch, which has a different plot function syntax. For the correct syntax of optimization plot functions, see http://www.mathworks.com/help/toolbox/optim/ug/f19175.html#bqxk733 or better http://www.mathworks.com/help/toolbox/optim/ug/f19175.html#f11022
Try modifying one of the optimization plot functions instead. For a list, see "PlotFcns" in http://www.mathworks.com/help/toolbox/optim/ug/f19175.html
Hope this helps,
Alan
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!