www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgpreclookupfix/cgpreclookupfix.m
function LookupFixPrec = cgpreclookupfix(TablePhysData, TableHWData, PhysRange, varargin) %CGPRECLOOKUPFIX Constructor for the cgpreclookupfix class. % % LOOKUPFIXPREC = CGPRECLOOKUPFIX(TablePhysData, TableHWData, ... % PhysRange, FIXPREC) constructs a cgpreclookupfix object LOOKUPFIXPREC % with a mapping from physical values to hardware values specified by a % lookup table [TablePhysData, TableHWData], a range PhysRange of % admissible physical values and a parent cgprecfix object FIXPREC. % % LOOKUPFIXPREC = CGPRECLOOKUPFIX constructs a cgpreclookupfix object % with default properties of TablePhysData = [0 1], TableHWData = [0 1], % PhysRange = [-Inf Inf] and a default parent cgprecfix object. % % LOOKUPFIXPREC = CGPRECLOOKUPFIX(TablePhysData, TableHWData) constructs % a cgpreclookupfix object with a default PhysRange = [-Inf Inf] and a % default parent cgprecfix object. % % LOOKUPFIXPREC = CGPRECLOOKUPFIX(TablePhysData, TableHWData, ... % PhysRange) constructs a cgpreclookupfix object with a parent % cgprecfix object FIXPREC. % % LOOKUPPREC = CGPRECLOOKUPFIX(TablePhysData, TableHWData, ... % PhysRange, bits, signed, ptpos, PREC) first constructs a parent % cgprecfix object cgprecfix(bits, signed, ptpos, PREC) and then uses % this cgprecfix object and to construct a cgpreclookupfix object % LOOKUPPREC = CGPRECLOOKUPFIX(TablePhysData, TableHWData, ... % PhysRange, bits, signed, ptpos, Name) is similar. % % See also CGPRECFIX, CGPREC % --------------------------------------------------------------------------- % Description : Constructor for the cgpreclookupfix class. % Inputs : TablePhysData - physical values column of the lookup table % that defines the mapping between physical % values and hardware values % TableHWData - hardware values column of the lookup table % that defines the mapping between physical % values and hardware values % PhysRange - physical range (dbl,1x2) % Opt Inputs : FIXPREC - cgprecfix object specifying the bits, % un/signed, the fixed point position and the % admissible physical range % bits - bits in the mantissa (int) % signed - sign flag to denote unsigned (0) or signed % (1) % ptpos - fixed point position (int) % PREC - cgprec object % Name - name used to construct a cgprec object % (char) % Outputs : LOOKUPFIXPREC - cgpreclookupfix object specifying table % data, interpolation method and the admissible % physical range % --------------------------------------------------------------------------- % Copyright 2000-2008 The MathWorks, Inc. and Ford Global Technologies, Inc. % Define object structure LookupFixPrecStruct = struct('TablePhysData',[],... 'TableHWData',[],... 'PhysRange',[]); % Error check on TablePhysData, TableHWData if nargin==0 % TablePhysData, TableHWData not specified, use the default values TablePhysData = i_check([], 'TablePhysData'); TableHWData = i_check([], 'TableHWData'); elseif nargin==1 % Too few input arguments error(message('mbc:cgpreclookupfix:InvalidArgument')); else % try to use TablePhysData, TableHWData if valid TablePhysData = i_check(TablePhysData, 'TablePhysData'); TableHWData = i_check(TableHWData, 'TableHWData'); if ~isequal(size(TablePhysData), size(TableHWData)) error(message('mbc:cgpreclookupfix:InvalidArgument1')) end end % Error check on PhysRange if nargin<=2 % PhysRange not specified, use the default value PhysRange = i_check([], 'PhysRange'); else % try to use PhysRange if valid PhysRange = i_check(PhysRange, 'PhysRange'); end % Error check on varargin (bits, signed, ptpos, cgprec object or comment) if nargin<4 % There are no extra inputs, construct a default cgprecfix object FixPrec = cgprecfix; elseif nargin==4 if isa(varargin{1}, 'cgprecfix') % There is one extra input that is a cgprecfix object FixPrec = varargin{1}; else % The extra input is not a valid cgprecfix object error(message('mbc:cgpreclookupfix:InvalidArgument2')); end else % There are three or four extra inputs that are bits, signed, ptpos and % optionally PREC/Name. Construct a cgprecfix object using cgprecfix % constructor with the extra arguments varargin as the constructor % inputs. Note that cgprecfix and cgprec have built-in error checking. FixPrec = cgprecfix(varargin{:}); end % Assemble object structure LookupFixPrecStruct.TablePhysData = TablePhysData; LookupFixPrecStruct.TableHWData = TableHWData; LookupFixPrecStruct.PhysRange = PhysRange; % Create object class LookupFixPrec = class(LookupFixPrecStruct ,'cgpreclookupfix', FixPrec); % ------------------------------------------------------------------------- function out = i_check(in, VarName) % Check input variables switch VarName case {'TablePhysData','TableHWData'} if ~isnumeric(in) % TablePhysData, TableHWData is nonnumeric error(message('mbc:cgpreclookupfix:InvalidArgument3', VarName)); elseif ~isreal(in) % TablePhysData, TableHWData is not real error(message('mbc:cgpreclookupfix:InvalidArgument4', VarName)); elseif length(in)<=1 % TablePhysData, TableHWData is too small, use default value out = [0 1]; else % TablePhysData, TableHWData is valid out = in; end case 'PhysRange' if isnumeric(in) && isreal(in) && isequal(size(in), [1 2]) % PhysRange is a real 1x2 array, sort in ascending order out = sort(in); else % PhysRange is not a real 1x2 array, use default value out = [-Inf Inf]; end end