www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptim/deleteObjectiveFunc.m

    function optim = deleteObjectiveFunc(optim, ObjectiveFuncLabel)
%DELETEOBJECTIVEFUNC Remove an objective from the optimization
%
%  OPTIM = DELETEOBJECTIVEFUNC(OPTIM, LABEL) removes the specified
%  objective from the optimization.

%  Copyright 2000-2009 The MathWorks, Inc. and Ford Global Technologies, Inc.


if ~canRemoveObjective(optim.OptimSetup)
    error(message('mbc:cgoptim:InvalidState6'));
end

if ischar(ObjectiveFuncLabel)
    index = getObjectiveIndex(optim.OptimSetup, ObjectiveFuncLabel);
elseif ObjectiveFuncLabel>0 && ObjectiveFuncLabel<=numObjectives(optim.OptimSetup)
    index = ObjectiveFuncLabel;
    lbls = getObjectiveLabels(optim.OptimSetup);
    ObjectiveFuncLabel = lbls{index};
else
    index = 0;
end

if index>0
    % Destroy the constraint
    optim.OptimSetup = removeObjective(optim.OptimSetup, ObjectiveFuncLabel);
    destroy(optim.Objectives{index});
    optim.Objectives(index) = [];
    optim.oppoints = deleteObjective(optim.oppoints,index);
end