Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: GA: extra parameters for fitness function
Date: Sun, 7 Dec 2008 21:34:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 14
Message-ID: <ghhfga$ts$1@fred.mathworks.com>
References: <32843526.1228587243063.JavaMail.jakarta@nitrogen.mathforum.org> <19810651.1228662479564.JavaMail.jakarta@nitrogen.mathforum.org>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1228685642 956 172.30.248.38 (7 Dec 2008 21:34:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 7 Dec 2008 21:34:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1338633
Xref: news.mathworks.com comp.soft-sys.matlab:505491


SabbeRubbish <SabbeRubbish@gmail.com> wrote in message <19810651.1228662479564.JavaMail.jakarta@nitrogen.mathforum.org>...
> I've found a solution to this problem, albeit not a very pretty one: using global variables (I know, it's bad practice but in this particular case I couldn't get around it, on such short notice).
> 
> So I just declare my fileName or colorImage as global:
> global colorImage;
> in both files (calling function and called fitness function).

Try to avoid using global variables where possible as they can cause problems depending on what your code does. To pass variables to a GA the fitness function must be specified as shown in the example below:

FitnessFcn=@(x)m_file_fitness_calc(x,other variables...)

then the ga is called using as: ga(FitnessFcn,other options...) etc.

hope that helps.