打开ga函数,从后往前找,大概400行左右,根据你的优化问题类型找到对应的求解函数,比如我之前用线性规划的时候就打开galincon这个函数,在galincon的第95行代码:state.Best(generation) = fval;后边添加以下两行代码:
output.fitever(generation) = fval;%######
output.bestpopulationever(generation,:) = state.Population(best,:);%#######
这样在调用ga函数的时候输出变量output这个结构体里就保存了历史最优适应度fitever和历史最优种群bestpopulationever。
更具体的可以参考以下两个链接:
