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

    function optim = setConstraint(optim, label, constraint)
%SETCONSTRAINT Update an existing constraint
%
%  OPTIM = SETCONSTRAINT(OPTIM, LABEL, CONSTRAINT) updates the specified
%  constraint to use the given new constraint object.
%
%  OPTIM = SETCONSTRAINT(OPTIM, CONSTRAINTS) sets a new cell array of all
%  the constraints.  The length of CONSTRAINTS must match the current number
%  of constraints in the optimization.

%  Copyright 2005-2007 The MathWorks, Inc. and Ford Global Technologies, Inc.


if nargin==3
    ind = getConstraintIndex(optim.OptimSetup, label);
    if ind==0
        error(message('mbc:cgoptim:InvalidLabel'));
    else
        % Make the constraint have the same name as the label
        constraint = setName(constraint, label);
        % Set the constraint
        optim.Constraints{ind} = constraint;
    end
else
    if numel(label)~=numel(optim.Constraints)
        error(message('mbc:cgoptim:InvalidArgument17'));
    end
    constraints = label;
    constraintlabels = getConstraintLabels(optim.OptimSetup);
    constraints = mbccellarrayeval(constraints, @setName, constraintlabels');
    optim.Constraints = constraints;
end