I have been looking how to create my own output function in GA to get each x and fval of each iteration and generation. Although I have looked into all the answered questions for such a question, nothing has been working so far. Here is my output function and please help me with what I'm missing.
function [state,options,optchanged] = gaoutfun(options,state,flag)persistent history_pop history_Best history_Scorehistory_pop = [];history_Best = [];history_Score = [];optchanged = false;switch flag case 'init' history_pop = [history_pop;state.Population]; assignin('base','gapopulationhistory',history_pop); history_Best = [history_Best;state.Best]; assignin('base','gabesthistory',history_Best); history_Score = [history_Score;state.Score]; assignin('base','gascorehistory',history_Score); case 'iter' history_pop = [history_pop;state.Population]; assignin('base','gapopulationhistory',history_pop); history_Best = [history_Best;state.Best]; assignin('base','gabesthistory',history_Best); history_Score = [history_Score;state.Score]; assignin('base','gascorehistory',history_Score); case 'done' history_pop = [history_pop;state.Population]; assignin('base','gapopulationhistory',history_pop); history_Best = [history_Best;state.Best]; assignin('base','gabesthistory',history_Best); history_Score = [history_Score;state.Score]; assignin('base','gascorehistory',history_Score); end
Best Answer