www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptimoptions/addFreeVariable.m
function obj = addFreeVariable(obj, sLabel) %ADDFREEVARIABLE Add a free variable to the optimization. % OPTIONS = ADDFREEVARIABLE(OPTIONS, LABEL) adds a placeholder for a free % variable to the optimization. The string LABEL will be used to refer % to the variable in the CAGE GUI. % % See also CGOPTIMOPTIONS/SETFREEVARIABLESMODE, % CGOPTIMOPTIONS/GETFREEVARIABLESMODE, % CGOPTIMOPTIONS/GETFREEVARIABLES, % CGOPTIMOPTIONS/REMOVEFREEVARIABLE. % Copyright 2000-2004 The MathWorks, Inc. and Ford Global Technologies, Inc. if ~ischar(sLabel) error(message('mbc:cgoptimoptions:InvalidArgument')); end % Check that the label is unique to other free variables ok = checklabel(obj, sLabel); if ~ok error(message('mbc:cgoptimoptions:NonUniqueLabel')); end % Check that there are no linear constraints mylincon = getLinearConstraints(obj); if ~isempty(mylincon) warning(message('mbc:cgoptimoptions:InvalidState')); else lbls = obj.freevariables.labels; N = length(lbls); lbls{N + 1} = sLabel; obj.freevariables.labels = lbls; end