how to use 'OutputFcn' in GA
9 views (last 30 days)
Show older comments
Dear All,
I'm trying to use the next function to find some information about previous generation and I found difficulty with writing the state and the options
options = gaoptimset('OutputFcn', @outputfun);
[state,options,optchanged] = outputfun(options,state,flag)
I have this code which is work,
function [x,fval,exitflag,output,population,score] = optimGA(nvars,lb,PopulationSize_Data,Generations_Data,TolFun_Data,InitialPopulation_Data)
%%This is an auto generated MATLAB file from Optimization Tool.
could you please explain to me how to write it. or you may have better idea
Thank you in advance
0 Comments
Answers (1)
Alan Weiss
on 27 Aug 2014
GA will pass in options, state, and flag. You should pass those exact same options and state to the output function output arguments, and set optchanged to false, unless for some reason you want to change the options during your output function call. See the documentation.
Alan Weiss
MATLAB mathematical toolbox documentation
2 Comments
Alan Weiss
on 27 Aug 2014
function[state,options,optchanged] = outputfun(options, state, flag)
optchanged = false;
% DO NOT set options, state, or flag!
% Just write code to calculate whatever it is you want here.
% If you need to read an option, then read it, don't set it.
% Make sure that your options include @outputfun as your output function.
Alan Weiss
MATLAB mathematical toolbox documentation
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!