MATLAB Answers

how can i save every generation's best position using ga

22 views (last 30 days)
li jian
li jian on 28 Mar 2014
Edited: Walter Roberson on 1 Jan 2019
i'm using the ga function in matlab, i want to save every generation's best position
how can i do that.becanse i cannot find
[x,fval,exitflag,output,population,scores] = ga(fitnessfcn,nvars,...)
return such values

  0 Comments

Sign in to comment.

Answers (1)

A Jenkins
A Jenkins on 28 Mar 2014
Use gaoptimset to change the options. Display and PlotFcns will show some detail. You may also want to look at the OutputFcns option where you can write your own custom function to collect data.
A = [1 1; -1 2; 2 1];
b = [2; 2; 3];
lb = zeros(2,1);
ga_options=gaoptimset('Display','iter','PlotFcns',@gaplotbestf);
[x,fval,exitflag,output,population,scores] = ga(@lincontest6,...
2,A,b,[],[],lb,[],[],ga_options);

  3 Comments

li jian
li jian on 29 Mar 2014
I appreciate it very much,thank you. I'm working on the OutputFcns option.But i have difficulty in writing my own custom function to collect every generation's best position and return the collected data. Will you please show me an example. I need it very much now
li jian
li jian on 31 Mar 2014
Hi Jenkins,I have solved the problem with the help of the custom plot function in PlotFcns option
zainab1996
zainab1996 on 1 Jan 2019
can you help with the code plz, i have the same problem

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by