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

    function opts = renameConstraint(opts, oldLabel, newLabel)
%RENAMECONSTRAINT Rename a constraint
%
%   OPTS = RENAMECONSTRAINT(OPTS, OLDLABEL, NEWLABEL) renames the
%   specified constraint. 
%
%   See also CGOPTIM/RENAMECONSTRAINT

%   Copyright 2007 The MathWorks, Inc.

% Do not allow rename if renameMode is false
if ~opts.renameMode
    error(message('mbc:cgoptimoptions:InvalidState5'));
end

% Do not allow if the new label is not unique
ok = checklabel(opts, newLabel);
if ~ok
    error(message('mbc:cgoptimoptions:NonUniqueLabel6'));
end

% If here, we should be able to rename the constraint
idx = getConstraintIndex(opts, oldLabel);
if idx
    opts.constraints.details(idx).label = newLabel;
else
    error(message('mbc:cgoptimoptions:InvalidState6'));
end