www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptim/deleteConstraint.m
function optim = deleteConstraint(optim, ConstraintLabel) %DELETECONSTRAINT Remove a constraint from the optimization % % OPTIM = DELETECONSTRAINT(OPTIM, CONNAME) removes the constraint that % matches the CONNAME string. % % OPTIM = DELETECONSTRAINT(OPTIM, INDEX) removes the specified constraint % from the constraints list. % Copyright 2000-2009 The MathWorks, Inc. and Ford Global Technologies, Inc. if ~canRemoveConstraint(optim.OptimSetup) error(message('mbc:cgoptim:InvalidState5')); end if ischar(ConstraintLabel) index = getConstraintIndex(optim.OptimSetup, ConstraintLabel); elseif ConstraintLabel>0 && ConstraintLabel<=numConstraints(optim.OptimSetup) index = ConstraintLabel; lbls = getConstraintLabels(optim.OptimSetup); ConstraintLabel = lbls{index}; else index = 0; end if index>0 % Destroy the constraint optim.OptimSetup = removeConstraint(optim.OptimSetup, ConstraintLabel); destroy(optim.Constraints{index}); optim.Constraints(index) = []; optim.ConstraintEnabled(index) = []; optim.oppoints = deleteConstraint(optim.oppoints,index); end