title: Unknown Bug Cause using MatLab's Genetic Algorithm
body: <p>I'm new to MatLab and I'm writing a MatLab GA program to solve a particular scheduling problem.  The problem is I can't figure out the cause of one particular error.  This is main program:</p>
  
  <pre><code>1 FitnessFcn = @(seq)rate_fitness(seq,batch,obs);
  2 MyPlotFcn = @(options,state,flag)rate_plot(options,state,flag,batch,seq,obs);
  3 options = gaoptimset('PopulationType','custom','PopInitRange',[1;obs]);
  4 options = gaoptimset(options,'CreationFcn',@rate_create,'CrossoverFcn', ...
      @rate_crossover,'MutationFcn',@rate_mutate,'PlotFcn',MyPlotFcn);
  5 [seq,objfunc,reason,output] = ga(FitnessFcn,obs,[],[],[],[],[],[],[],options);
  </code></pre>
  
  <p>Here is the rate_plot function:</p>
  
  <pre><code>function state = rate_plot(options,state,flag,batch,seq,obs)
  if strcmpi(flag,'init')
      cla;
  end
  {some code that works by itself}
  end
  </code></pre>
  
  <p>Here is the rate_create function:</p>
  
  <pre><code>function pop = create_permutations(NVARS,FitnessFcn,options)
  totalPopulationSize = sum(options.PopulationSize);
  n = NVARS;
  pop = cell(totalPopulationSize,1);
  for i = 1:totalPopulationSize
      pop{i} = randperm(n);
  end
  </code></pre>
  
  <p>The error I get (but ONLY when the 'PlotFcn' option is included) is:</p>
  
  <pre><code>Undefined function or variable 'seq'.
  
  Error in @(options,state,flag)rate_plot(options,state,flag,batch,seq,obs)
  
  Error in gadsplot&gt;callOnePlotFcn (line 179)
  optimvalues = plotfcn(varargin{1:end});
  
  Error in gadsplot (line 132)
  [state,optimvalues] = callOnePlotFcn(fname, plotNames{i}, state, options, ...
  optimvalues, 'init', args{i}{:});
  
  Error in gaunc (line 54)
  state = gadsplot(options,state,currentState,'Genetic Algorithm');
  
  Error in ga (line 348)
  [x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
  
  Error in rate_run (line 5)
  [seq,objfunc,reason,output] = ga(FitnessFcn,obs,[],[],[],[],[],[],[],options);
  </code></pre>
  
  <p>Anyone have any ideas?  Tanks!</p>