Matlab genetic algorithm plotobjective error
Afficher commentaires plus anciens
Hi! I used Matlab ga (genetic algorithm) for optimization. I wrote my objective function in a separate .m file. when I run the main code there is no problem and I get the optimal response; However, I cannot run the objfun on its own by pressing Run button. Now, I want to use ''plotobjective'' command in my main code, but the error appears about objective function. My first question is: can I use plotobjective as a command in my main .m file? If yes, how can I fix the problem of my objective function to plot my objective function?
The objective function that I wrote in a separate file is :
function f = objfun(x,a,b)
x1 = x(1:24);
y1 = x(25:end);
f = -mean (x1*a')+mean(y1*b');
end
''x1'' and ''y1'' are 1x24 vectors and ''a'' and ''b'' are calculated in my main file and are constant 1x24 vectors. so, at the end f (objective function) is a scalar.
In the main file I wrote: fun = @(x)objfun(x,a,b);
and I use below command to get the plot of objective function: plotobjective(fun,[-2 2; -2 2]);
Would you please tell me why the error appears about the objective function and how can I fix it? Thanks!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Genetic Algorithm dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!