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

    classdef (Hidden) mbcmodeloutput < mbclabel
%MBCMODELOUTPUT model output signal information and transforms
%
% obj = mbcmodeloutput(model);
% obj = mbcmodeloutput('Name',nm,'Units',units,'Transform',TransformString);
% obj = mbcmodeloutput(mbcmodeloutput);

%  Copyright 2007-2009 The MathWorks, Inc.
    
    properties (Dependent)
        BoxCox
        Transform
    end
    
    properties (SetAccess = private,GetAccess = private)
        TransformObject='';
        OutputVersion = 1;
    end
    
    methods 
        
        function obj = mbcmodeloutput(varargin)
            %MBCMODELOUTPUT constructor
            %
            % obj = mbcmodeloutput(model);
            % obj = mbcmodeloutput('Name',nm,'Units',units,'Transform',TransformString);
            % obj = mbcmodeloutput(mbcmodeloutput);
            

            if nargin
                if isa(varargin{1},'mbcmodeloutput')
                    obj = varargin{1};
                else
                    % prop,value pairs
                    for i=1:2:nargin
                        obj.(varargin{i}) = varargin{i+1};
                    end
                end
            end

        end
        
        
        function val = get.Transform(obj)
            %GET.TRANSFORM string of transform expression
            val = TransformLabel(obj,'y');
        end
        
        function obj = set.Transform(obj,val)
            %SET.TRANSFORM string of transform expression
           if isempty(val)
               obj.TransformObject = '';
           else
               obj.TransformObject = mbctransform(val);
           end
        end

        
        function val = get.BoxCox(obj)
            %GET.BOXCOX get boxcox power transform
            if isempty(obj.TransformObject) 
                val = 1;
            elseif isa(obj.TransformObject,'mbcboxcox')
                val = obj.TransformObject.Lambda;
            else
                Texpr = char(obj.TransformObject);
                lind = strfind(Texpr,'log');
                if ~isempty(lind)
                    val=0;
                else
                    % Try to decipher the non-log transform.
                    pwrind=find(Texpr=='^');
                    mnsind=find(Texpr=='-');
                    strend=mnsind(mnsind>pwrind+2);
                    [val, Nv] = sscanf(Texpr(pwrind+1:strend-1), '(%g)', 1);
                    if Nv==0
                        % No boxcox value found => no boxcox
                        val = 1;
                    end
                end

            end
        end

        function obj = set.BoxCox(obj,val)
            %SET.BOXCOX set boxcox power transform
            if isa(obj.TransformObject,'mbcboxcox')
                obj.TransformObject.BoxCox = val;
            else
                obj.TransformObject = mbcboxcox(val);
            end
        end
        
        function out = yinfo(obj,yi)
            %YINFO method for legacy calls from models
            if nargin == 1
                out.Name = obj.Name;
                out.Symbol = obj.Symbol;
                out.Units = obj.Units;
            elseif isstruct(yi) && all(ismember({'Name','Units','Symbol'},fieldnames(yi)))
                obj.Name = yi.Name;
                obj.Symbol = yi.Symbol;
                obj.Units = yi.Units;
                out = obj;
            else
                error(message('mbc:mbcoutput:InvalidArgument'))
            end
        end
        
        function str = TransformLabel(obj,s,type,TeX)
            %TRANSFORMLABEL label for transform
            %
            % str = TransformLabel(obj,s,type,TeX)
            %   Note that this routine returns a vectorized expression
            %   (with .*, .^ etc).
            
            if nargin<3
                type = 'fcn';
            end
            if nargin<2 || isempty(s)
                s = obj.Symbol;
            end
            if nargin>3 && TeX
                s = detex(s);
            end
            if ~isempty(obj.TransformObject)
                str = texlabel(obj.TransformObject,s,type);
            elseif any(strcmp(type,{'fcn','inv'}))
                str = '';
            else
                % derivative and inverse derivative should be one.
                str = '1';
            end
        end
        
        function str = functionString(obj,s,type)
            %FUNCTIONSTRING expression string to use in Simulink and Symbolic
            %
            % The expression is devectorized.
            
            str = TransformLabel(obj,s,type,false);
            %devectorize expression
            str= strrep(str,'.^','^');
            str= strrep(str,'.*','*');
            str= strrep(str,'./','/');
            str= strrep(str,'.\','\');
            
        end
        
       function HasTrans = HasTransform(obj)
           %HASTRANSFORM true if model has output transform
           %
           % HasTrans = HasTransform(m)
           
           HasTrans = ~isempty(obj.TransformObject);
       end
        
        function obj = set.TransformObject(obj,Value)
            %SET.TRANSFORMOBJECT internal transform object (mbctransform)
           if isa(Value,'mbctransform') || isempty(Value)
               obj.TransformObject = Value;
           else
               obj.TransformObject = mbctransform(Value);
           end
        end
            
        function y = doTransform(obj,y)
            %DOTRANSFORM do transform on input data
            
            if ~isempty(obj.TransformObject)
                y = obj.TransformObject.Fcn(y);
            end
        end
        function y = doInverse(obj,y)
            %DOINVERSE do inverse transform on input data
            if ~isempty(obj.TransformObject)
                y = obj.TransformObject.Inv(y);
            end
        end

        function y = doDiff(obj,y)
            %DODIFF do derivative of transform on input data
            if ~isempty(obj.TransformObject)
                y = obj.TransformObject.Diff(y);
            else
                y = ones(size(y));
            end
        end
        function y = doDiffInv(obj,y)
            %DODIFFINV do derivative of inverse transform on input data
            if ~isempty(obj.TransformObject)
                y = obj.TransformObject.DiffInv(y);
            else
                y = ones(size(y));
            end
        end
        
        
    end
end