MATLAB: How to obtain and view the automatic generated initial population from GA from Optimization Toolbox 5.1 (R2010b)

algorithmgagenericinitialOptimization Toolboxoutputfcnspopulation

I use the function GA without any given initial population and I want to view the initial population generated or produced by GA.

Best Answer

To see the intial population, one can specify or set the 'OutputFcns' property from the option used by GA. The function set by 'OutputFcns' gets called every itteration.
First write a function MATLAB file called my_view containing
function [state, options,optchanged] = my_view(options,state,flag,interval)
optchanged = false;
disp(state.Population)
end
Now set the 'OutputFcns' property to this function via
options = gaoptimset('OutputFcns',@my_view);
Finally call the GA function with this specified option
x = ga(fitnessfcn,nvars,options)