查看定点数据
在 Fixed-Point Designer™ 软件中,fipref 对象确定 fi 对象的显示属性。对于 fi 对象,代码示例通常在它们与下列 fipref 对象属性一起使用时才显示它们:
NumberDisplay—'RealWorldValue'NumericTypeDisplay—'full'FimathDisplay—'full'
通过将 'FimathDisplay' 设置为 'full',可以快速、轻松地区分具有局部 fimath 配置的 fi 对象和那些与默认 fimath 配置相关联的对象。当 'FimathDisplay' 设置为 'full' 时,MATLAB® 显示具有局部 fimath 配置的 fi 对象的 fimath 对象属性。MATLAB 不会显示与默认 fimath 配置相关联的 fi 对象的 fimath 对象属性。由于存在这种显示差异,您只需通过查看输出即可知道 fi 对象是否与默认 fimath 配置相关联。
此外,除非另有说明,否则整个 Fixed-Point Designer 文档中的示例都使用 fimath 的以下默认配置:
RoundingMethod: Nearest
OverflowAction: Saturate
ProductMode: FullPrecision
SumMode: FullPrecision
有关显示设置的详细信息,请参阅Set fi Object Display Preferences Using fipref。
显示 fi 对象的 fimath 属性
要查看大多数 Fixed-Point Designer 代码示例中显示的输出,请按如下所示设置 fipref 属性并创建两个 fi 对象:
p = fipref('NumberDisplay','RealWorldValue',... 'NumericTypeDisplay','full','FimathDisplay','full'); a = fi(pi,'RoundingMethod','Floor','OverflowAction','Wrap') b = fi(pi)
MATLAB 返回以下内容:
a =
3.1415
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 13
RoundingMethod: Floor
OverflowAction: Wrap
ProductMode: FullPrecision
SumMode: FullPrecision
b =
3.1416
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 13MATLAB 在 fi 对象 a 的输出中显示 fimath 对象属性,因为 a 具有局部 fimath 配置。
MATLAB 在 fi 对象 b 的输出中不显示任何 fimath 对象属性,因为 b 将自身与默认 fimath 关联。
隐藏 fi 对象的 fimath 属性
如果您正在使用多个具有局部 fimath 配置的 fi 对象,则可能需要关闭 fimath 对象显示:
NumberDisplay—'RealWorldValue'NumericTypeDisplay—'full'FimathDisplay—'none'
例如,
p = fipref('NumberDisplay','RealWorldValue',... 'NumericTypeDisplay','full','FimathDisplay','none')
p =
NumberDisplay: 'RealWorldValue'
NumericTypeDisplay: 'full'
FimathDisplay: 'none'
LoggingMode: 'Off'
DataTypeOverride: 'ForceOff'F = fimath('RoundingMethod','Floor','OverflowAction','Wrap'); a = fi(pi, F)
a =
3.1415
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 13尽管此设置有助于减少产生的输出量,但它也导致无法根据输出判断 fi 对象是否使用默认 fimath。为此,您可以使用 isfimathlocal 函数。例如,
isfimathlocal(a)
ans = logical 1
当 isfimathlocal 函数返回 1 时,fi 对象具有局部 fimath 配置。如果函数返回 0,则 fi 对象使用默认 fimath 配置。
缩短 fi 对象的 numerictype 显示
要进一步减少输出量,可以将 NumericTypeDisplay 设置为 'short'。例如,
p = fipref('NumberDisplay','RealWorldValue',... 'NumericTypeDisplay','short','FimathDisplay','full'); a = fi(pi)
a =
3.1416
numerictype(1,16,13)