Writing custom plot functions in optimisation

4 次查看(过去 30 天)
Hi. I'm using multiStart routine and I'm struggling to write a plot function that shows the start pint, and optimum point in each set of the local algorithm runs. To do this I think I need to pass the solutions array ( output from run fucntion) to my plot function as an input like below- but matlab has difficulty callling it- even when I set it as a Global variable the array appears as empty in the workspace and I receive the error: too many input arguments!
Questions: 1- If this is wrong what is a better way of calling the start point X0 and optimum solution X apart from calling solutions?
Question: 2- Are the middle points saved anywhere during the process? I need to plot the path from start to end point.
Thanks for the help
function stop = myplotfcn(solutions,state)
stop = false;
switch state
case 'done'
figure; hold on
for i=1:soluno
x0=solutions(1,i).X0;
x0=cell2mat(x0);
x=solutions(1,i).X;
h1=plot(x0(1),x0(2),'b*');
plot([x0(1) x(1)],[x0(2) x(2)],'k');
h2=plot(x(1),x(2),'r*');
legend([h1,h2],'start point','optimum');
end
hold off
end

采纳的回答

Alan Weiss
Alan Weiss 2012-4-23
As explained in http://www.mathworks.com/help/toolbox/gads/bsc59_4.html#bsk8q3m, the syntax for a plot function is the same as that for an output function: http://www.mathworks.com/help/toolbox/gads/bsdkjr5.html#bsk8r2p,
The syntax is stop = outFcn(optimValues,state) where optimValues is a structure described in http://www.mathworks.com/help/toolbox/gads/bsdkjr5.html#bsk8sd3.
You are attempting to pass solutions instead of the name of the structure field. The contents of the optimValues structure are filled in by MultiStart as it runs. It contains the following information:
*bestx — The current best point *bestfval — Objective function value at bestx *funccount — Total number of function evaluations *localrunindex — Index of the local solver run *localsolution — A structure containing part of the output of the local solver call: X, Fval and Exitflag
However, instead of calling a plot function, perhaps an example in the documentation does what you want: http://www.mathworks.com/help/toolbox/gads/bsc59_4.html#bsc89tq
Good luck,
Alan Weiss MATLAB mathematical toolbox documentation

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by