www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xregusermod/checkmodel.m

    function OK= checkmodel(U)
%CHECKMODEL
% 
% OK= checkmodel(U)

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


OK=1;
if ~isGrowth(U)
    uname = name(U);
    U.ThrowError = true;

    try
        % check MATLAB file exists
        nf= feval(U.funcName,U,'nfactors');
    catch causeME
        ME = MException('mbc:xregusermod:InvalidModel',...
            'User-defined MATLAB File %s.m is not found',uname);
        ME = addCause(ME,causeME);
        throw(ME)
    end
    
    if ~isnumeric(nf) || ~isscalar(nf) || nf~=fix(nf) || nf<1
        % check that the number of inputs is a positive integer
        error(message('mbc:xregusermod:InvalidModel', uname))
    end

    if nfactors(U)~=nf
        % check that the number of inputs hasn't changed
        error(message('mbc:xregusermod:InvalidModel12', uname))
    end

    np = feval(U.funcName, U, 'numparams');
    if ~isnumeric(np) || ~isscalar(np) || np~=fix(np) || np<1
        error(message('mbc:xregusermod:InvalidModel13', uname))
    end
    if np~=length(double(U))
        % check that the parameters are consistent
        error(message('mbc:xregusermod:InvalidModel14', uname))
    end
    
    try
        [LB,UB]= range(U);
        x= (LB+UB)/2;
        feval(U.funcName,U,x);
    catch causeME
        ME = MException('mbc:xregusermod:InvalidModel',...
            'Cannot evaluate user-defined model ''%s''',uname');
        ME = addCause(ME,causeME);
        throw(ME);
    end

    % check in list (add if not)
    USERMODELS= getpref(mbcprefs('mbc'),'usermodels');
    if ~any(strcmp(name(U),USERMODELS.models))
        % add to list
        modelcfg(U);
    end

end