www.gusucode.com > mbc 工具箱 matlab 源码程序 > mbc/@mbcmodel/@data/ModifyVariable.m

    function D = ModifyVariable(D, index, expr, varargin)
%MODIFYVARIABLE Modify a user-defined variable in a data set.
%
%   D = MODIFYVARIABLE(D, VARIABLE_INDEX, NEW_VARIABLE_EXPRESSION, NEW_VARIABLE_UNITS);
%
%   See also mbcmodel.data.AddVariable, mbcmodel.data.RemoveVariable.

%   Copyright 2004-2007 The MathWorks, Inc.

error(mbcnargchk(3, 4, nargin, 'mbc:mbcmodel:data'));

% Make sure that the object is editable
D.pCheckIsBeingEdited;
try
    % Make sure the index is correct
    if index < 1 
        error(message('mbc:mbcmodel:data:InvalidIndex6'));
    end
    if index > numVariables(D.Object)
        error(message('mbc:mbcmodel:data:InvalidIndex7'));                
    end
    % Call the underlying method
    D.Object = modifyVariable(D.Object, index, expr, varargin{:});
catch E
    [mnemonic, component] = mbcGetLastError(E);
    switch [component ':' mnemonic]
        case 'data:InvalidIndex'
            error('mbc:mbcmodel:data:InvalidIndex8', E.message);                
        otherwise
            error(message('mbc:mbcmodel:data:UnknownError11'));    
    end
end