liefert leider immer nur die letzte Generation. Weiß jemand wie man dies macht? Das Kapitel Outputfunctions aus der Dokumentation bringt mich leider nicht weiter.
die Vorlage aus der Dokumentation habe ich übernommen, auch wenn ich noch nciht ganz verstanden habe warum ich die switch case Sache einfügen muss. Also meine myfun sieht so aus:
Code:
function[x,options,optchanged] =myfun (options,state,flag)
optchanged = false;
if ~isfield(state,'Population') title('Rank Histogram: not available','interp','none');
return;
end
switch flag
case 'init'
disp('Starting the algorithm');
x=state.Population;
case{'iter','interrupt'} disp('Iterating ...')
x=state.Population case 'done'
disp('Performing final task');
Das hier ist übrigens noch der Code von gaoutput bis zu Zeile 32
Code:
function[state,options,optchanged] = gaoutput(~,options,state,flag)
%GAOUTPUT Helper function that manages the output functions for GA.
%
% [STATE, OPTIONS, OPTCHANGED] = GAOUTPUT(~, OPTIONS, STATE, FLAG) % runs each of the display functions in the options.OutputFcns cell % array.
%
% This is a helper function called by ga between each generation, and is % not typically called directly.
% Copyright 2003-2011 The MathWorks, Inc. % $Revision: 1.1.6.5 $ $Date: 2012/10/24 04:18:01 $
% get the functions and return if there are none
optchanged = false;
functions = options.OutputFcns;
if(isempty(functions)) return end
% call each output function
stopFlag = [];
args = options.OutputFcnsArgs;
for i = 1:length(functions) % Always clear state.StopFlag before calling OutputFcns so that each % function can independently set a termination message.
state.StopFlag = '';
[state,optnew,changed] = feval(functions{i},options,state,flag,args{i}{:});
if ~isempty(state.StopFlag)
stopFlag = [stopFlag state.StopFlag ';'];
end
Okay, alles klar dann habe ich es denke ich verstanden. x ist ja in meinem Falle kein struct mehr, weil ich die Werte von Population auf x ablege.
Habs geändert, jetzt klappt es. Vielen Dank für den Tipp!
Simon
Einstellungen und Berechtigungen
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.