www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgpreclookupfix/phys2hw.m
function HWValues = phys2hw(LOOKUPFIXPREC, PhysValues) %PHYS2HW Convert physical values to hardware values. % % HWValues = PHYS2HW(POLYFIXPREC, PhysValues) converts physical values % PhysValues to hardware values HWValues using a lookup table and % hardware precision described by the cgpreclookupfix object % LOOKFIXUPPREC. % Copyright 2000-2006 The MathWorks, Inc. and Ford Global Technologies, Inc. % Error check on PhysValues PhysValues = i_check(PhysValues, 'PhysValues'); % Clip the physical values to range specified by PhysRange PhysValues = physresolve(LOOKUPFIXPREC, PhysValues); % Fetch lookup table data and interpolation method for the physical to % hardware conversion TablePhysData = get(LOOKUPFIXPREC, 'TablePhysData'); TableHWData = get(LOOKUPFIXPREC, 'TableHWData'); % Clip out of range values to the min/max of the table input range PhysValues = min(PhysValues, TablePhysData(end)); PhysValues = max(PhysValues, TablePhysData(1)); % Find HWValues by linear interpolation, see 'help interp1' for more info HWValues = interp1(TablePhysData, TableHWData, PhysValues); % Round the pseudo-hardware values to the nearest admissible values HWValues = hwresolve(LOOKUPFIXPREC, HWValues); % ------------------------------------------------------------------------- function out = i_check(in, VarName) % Check input variables switch VarName case 'PhysValues' if ~isnumeric(in) % PhysValues is nonnumeric error(message('mbc:cgpreclookupfix:InvalidArgument5')); elseif ~isreal(in) % PhysValues is not real error(message('mbc:cgpreclookupfix:InvalidArgument6')); else % PhysValues is valid out = in; end % if end % switch