Hi,
I want to define a custom plotfunction for my optimization. It should be a bit like the standard 'optimplotfval' plot function, but with a few extras. The information available is a bit unclear to me. It says that I have to define it just like the OutFnc, which I'm using too. If I'm using the same structure, I get an error message:
??? Error using ==> opt>objectiveconstraints/plotfunToo many output arguments.Error in ==> callAllOptimPlotFcns at 62 state(i) = feval(plotNames{i},x,optimvalues,'init',varargin{:});Error in ==> nlconst>callOutputAndPlotFcns at 1032 stop = callAllOptimPlotFcns(plotfcns,xOrigShape,optimValues,state,varargin{:}) || stop;Error in ==> nlconst at 559 [xOrigShape, optimValues, stop] = callOutputAndPlotFcns(outputfcn,plotfcns,caller,problemInfo, ...Error in ==> fmincon at 724 [X,FVAL,LAMBDA,EXITFLAG,OUTPUT,GRAD,HESSIAN]=...Error in ==> opt>objectiveconstraints at 260 [x,fval] = fmincon(problem);Error in ==> opt at 50[x,fval,aircraft] = objectiveconstraints(aircraft,problem);
I have defined my plot function in the same way as the OutFnc:
%Define function handles
objective=@(x)obj(aircraftstart,x); constraint=@con; outputfunction=@outfun; plotfunction=@plotfun;
The function is nested inside the main function and looks like this:
function [] = plotfun(x,optimValues,state) figure(20) hold on if optimValues.constrviolation<=1E-6 plot(optimValues.iteration,optimValues.fval,'g') else plot(optimValues.iteration,optimValues.fval,'r') end hold off end
I don't have any output from the plot function, yet it still says I have too many output arguments. The options of fmincon are:
problem.options = optimset('Display','iter','MaxIter',1000,'OutputFcn',outputfunction,'FunValCheck','on','Algorithm','active-set','DiffMinChange',0.05,'DiffMaxChange',10.0,'PlotFcns',plotfunction,'TolX',1e-20);
Any thoughts?
Best Answer