www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptim/addObjectiveFunc.m
function optim = addObjectiveFunc(optim, label) %ADDOBJECTIVEFUNC Add a new objective to the optimization % % OPTIM = ADDOBJECTIVEFUNC(OPTIM, LABEL) adds a new objective labelled % with the given LABEL. If LABEL is omitted, a default will be chosen % that is unique from other objectives. % Copyright 2000-2009 The MathWorks, Inc. and Ford Global Technologies, Inc. if ~canAddObjective(optim.OptimSetup) error(message('mbc:cgoptim:InvalidState1')); end if nargin < 2 label = 'Objective'; label = generateLabel(optim.OptimSetup, label); elseif ~ischar(label) error(message('mbc:cgoptim:InvalidArgument2')); else label = generateLabel(optim.OptimSetup, label, 'allowroot'); end % Add a new objective to the setup optim.OptimSetup = addObjective(optim.OptimSetup, label, 'min/max'); % Allow new objectives to be either min or max (default min) optimobj = cgpointobjective(label, 'Minimize'); optimobj = setAllowTypeChange(optimobj, true); optim.Objectives = [optim.Objectives, {optimobj}]; optim.oppoints = addObjective(optim.oppoints);