www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptim/setObjectiveFunc.m
function optim = setObjectiveFunc(optim, label, objective) %SETOBJECTIVEFUNC Update an existing objective % % OPTIM = SETOBJECTIVEFUNC(OPTIM, LABEL, OBJECTIVE) updates the specified % objective to use the given new objective object. % % OPTIM = SETOBJECTIVEFUNC(OPTIM, OBJECTIVES) sets a new cell array of all % the objectives. The length of OBJECTIVES must match the current number % of objectives in the optimization. % Copyright 2005-2007 The MathWorks, Inc. and Ford Global Technologies, Inc. if nargin==3 ind = getObjectiveIndex(optim.OptimSetup, label); if ind==0 error(message('mbc:cgoptim:InvalidLabel7')); else % Make the objective have the same name as the label objective = setName(objective, label); % set the objective optim.Objectives{ind} = objective; end else if numel(label)~=numel(optim.Objectives) error(message('mbc:cgoptim:InvalidArgument21')); end objectives = label; objectivelabels = getObjectiveLabels(optim.OptimSetup); objectives = mbccellarrayeval(objectives, @setName, objectivelabels'); optim.Objectives = objectives; end