# How to pass variables to the fintness function in Genetic algorithm?

2 vues (au cours des 30 derniers jours)
Mariem Harmassi le 8 Oct 2012
hello I am testing a Genetic algorithm without using the global optimization toolbox, I have defined the fitness function in a separtae matlab file and it is called by the main program with ga function ,in my fitness function i need some parametrs from the main function .Can someone tell me hwo to do this ?? I thought about declaring the variables as global variables but it doesn t work ?
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Alan Weiss le 10 Oct 2012
Alan Weiss
MATLAB mathematical toolbox documentation
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Mariem Harmassi le 11 Oct 2012
Hello Alan thank u for the answer , i saw the documentation but it seems not possible to call the ga with f = @(x)parameterfun(x,a,b,c) i must call the fminunc function [x,fval] = fminunc(f,x0) :-/ :-(

Connectez-vous pour commenter.

### Plus de réponses (3)

Alan Weiss le 11 Oct 2012
I'm sorry, I do not understand you. It is indeed possible to call the fitnes function with f = @(x)parameterfun(x,a,b,c). If you want more help, you will need to provide more information. Specifically:
1. Your function signature (function f = parameterfun(x,a,b))
2. Your calling syntax (x = ga(f,n,A,b))
3. All output MATLAB gives. I mean all, not an edited version.
Alan Weiss
MATLAB mathematical toolbox documentation
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Mariem Harmassi le 13 Oct 2012
thank u a lot Alan i tested it and it works so i am very happy :)))

Connectez-vous pour commenter.

Alex Omar Topa Gavilema le 3 Juin 2022
I have the same problem. how did you do it?
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

M Mirrashid le 5 Juin 2022
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by