www.gusucode.com > mbcexpr 工具箱 matlab 源码程序 > mbcexpr/@cgsymvalue/updatenames.m
function obj = updatenames(obj) %UPDATENAMES Update the formula's variables % % OBJ = UPDATENAMES(OBJ) updates the names of the variables in the formula % from the current names of the input value objects. % Copyright 2000-2011 The MathWorks, Inc. and Ford Global Technologies, Inc. if ~isempty(obj.EquationString) eqptrs = obj.EquationPointers; sOldNames = obj.EquationInputs; sNewNames = cell(size(sOldNames)); for n = 1:length(eqptrs) if isnull(eqptrs(n)) % No link: keep current name sNewNames{n} = sOldNames{n}; else thisobj = eqptrs(n).info; % get the alias this input has aliaslist = getaliaslist(thisobj); % if the equation uses an alias, we'll keep the alias if ismember( sOldNames{n}, aliaslist ) sNewNames{n} = sOldNames{n}; else sNewNames{n} = getname(thisobj); end end end % convert from inline to sym sEq = sym(obj.EquationObject); % do the substitution(s) sEq = subs( sEq, sOldNames, sNewNames ); % convert back to a string eqstr = char( sEq ); % Create new equation objects eqobj = mbcinline(eqstr); inveqobj = createinverse(getname(obj), eqstr, sNewNames{obj.EquationVariableIndex}); % Reorder pointers to match new argnames order [nul, idx] = sort(sNewNames); eqptrs = eqptrs(idx); [nul, idx] = sort(idx); obj.EquationVariableIndex = idx(obj.EquationVariableIndex); obj.EquationString = eqstr; obj.EquationInputs = argnames(eqobj); obj.EquationPointers = eqptrs; obj.EquationObject = eqobj; obj.InverseObject = inveqobj; end