www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgddnode/convtoformula.m

    function [ok, msg] = convtoformula(dd, pVar, rhsStr)
%CONVTOFORMULA Convert item to a formula
%
%  [OK, MSG] = CONVTOFORMULA(DD, PITEM) converts any variable dictionary
%  item into a formula.
%  
%  [OK, MSG] = CONVTOFORMULA(DD, PITEM, NEWRHS ) uses the specified string
%  as a formula.

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


ok = false;
msg = '';
if ~pVar.issymvalue
    mySym = insymval(dd, pVar);
    if isempty(mySym)
        oldobj = pVar.info;
        SV = cgsymvalue;
        SV = copybaseinfo(oldobj, SV);
        if ~isconstant(oldobj)
            SV = setrange(SV, getrange(oldobj));
        end
        pDD = address(dd);

        if nargin==2
            [SV, ok] = editequation(SV, pDD, pVar.getname );
        elseif nargin==3 && ischar( rhsStr )
            [SV, flags] = setequation( SV, rhsStr, pDD );
            SV = updaterange( SV );
            ok = all(flags);
        end

        if ok
            setaddress(SV, pVar);
            dd = pDD.info;
            dd.numsymvars = dd.numsymvars + 1;
            xregpointer(dd);
        end
    else
        msg = 'Unable to convert to formula because the item is currently being used by another formula.';
    end
else
    % No work to do
    ok = true;
end