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

    function Prec = set(Prec, PropertyName, PropertyValue)
%SET Set properties of a cgprecfix object.
%
%   FIXPREC = SET(FIXPREC, PropertyName, PropertyValue) modifies the
%   property PropertyName of a cgprecfix object FIXPREC to a value
%   PropertyValue.
%
%   See also  CGPRECFIX

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


% Try to use extra input as a property name if valid
switch lower(PropertyName)
    case 'bits'
        % Set bits
        Prec.bits = PropertyValue;
        % Update dependent object properties
        Prec = i_update(Prec);
    case 'signed'
        % Set signed
        Prec.signed = PropertyValue;
        % Update dependent object properties
        Prec = i_update(Prec);
    case 'ptpos'
        % Set ptpos
        Prec.ptpos = PropertyValue;
        % Update dependent object properties
        Prec = i_update(Prec);
    otherwise
        % No valid property name at this level, try the superclass
        Prec.cgprec = set(Prec.cgprec, PropertyName, PropertyValue);
end


% -------------------------------------------------------------------------
function Prec = i_update(Prec)

% Update dependent object properties HWRange and HWResolution

% Update HWResolution
Prec.HWResolution = 1/(2^Prec.ptpos);

% Update HWRange
if Prec.signed==0
    % unsigned
    Prec.HWRange = [0 2^Prec.bits-1]/(2^Prec.ptpos);
else
    % signed
    Prec.HWRange = [1-2^(Prec.bits-1) 2^(Prec.bits-1)]/(2^Prec.ptpos);
end