www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgfuncmodel/cgfuncmodel.m

    classdef cgfuncmodel < xregexportmodel
    %CGFUNCMODEL CAGE function model class
    %
    %  for internal use
    
    %  Copyright 2000-2009 The MathWorks, Inc. and Ford Global Technologies, Inc.
    
    properties(Access=private)
        %FUNC string containing function expression
        func='';
        %FUNCV anonymous function handle to expression 
        %    This function must be vectorized.
        funcv
    end
    properties(Access=private)
        Version=3
    end 
    
    methods
        function f = cgfuncmodel(str, symbols ,name)
            %CGFUNCMODEL Constructor for the cgfuncmodel class
            %
            %  CGFUNCMODEL returns a new empty cgfuncmodel object.
            %
            %  CGFUNCMODEL(FUNC, SYMBOLS, NAME) creates a new cgfuncmodel from the
            %  given function string, input symbols and model name.  If NAME is omitted
            %  the default name of 'function' will be used.  If SYMBOLS is omitted the
            %  default symbols will be extracted from the function string
            %  automatically.
    
            if nargin 
                if isa(str, 'cgfuncmodel')
                    [f, ok, msg] = setfunction(f, get(str, 'function'), getsymbols(str));
                elseif nargin>1
                    [f, ok, msg] = setfunction(f, str, symbols);
                else
                    [f, ok, msg] = setfunction(f, str);
                end
                if ~ok
                    error('mbc:cgfuncmodel:InvalidFunction', msg);
                end
                
                if nargin > 2
                    f = setname(f,name);
                else
                    f = setname(f,'function');
                end
            end
            
        end
    end
    
    methods(Static)
        function f = loadobj(f)
            %LOADOBJ Load an old object
            %
            %  OBJ = LOADOBJ(OBJ) is called when an object is loaded.
            
            if isstruct(f) 
                funcdef = f.func;
                if isa(f.func, 'inline') || ischar(funcdef)
                    % Some intermediate object versions kept an inline instead of the
                    % original char and are missing symbol information in the parent
                    funcdef= char(funcdef);
                    symb = symvar(funcdef);
                end
                
                % old OOPS
                NewObj = cgfuncmodel;
                f = copyToExportModel(NewObj,f.xregexportmodel);
                if ischar(funcdef)
                    
                    f = setfunction(f, funcdef, symb, false);
                else
                    f.func = funcdef;
                end
            end
        end
    end
end