主要内容

numerictype

创建描述定点或浮点数据类型的 embedded.numerictype 对象

说明

numerictype 对象允许您设置确定 fi 对象如何将存储数据解释为真实值的属性。

创建对象

使用此处描述的 numerictype 函数创建一个 numerictype 对象。

描述

T = numerictype 创建一个默认的 numerictype 对象。

示例

T = numerictype(s) 创建一个定点 numerictype 对象,该对象未指定定标类型,具有有符号属性值 s 和 16 位字长。

示例

T = numerictype(s,w) 创建一个定点 numerictype 对象,该对象未指定定标类型,具有有符号属性值 s 和字长 w

示例

T = numerictype(s,w,f) 创建一个定点 numerictype 对象,该对象具有二进制小数点定标、有符号属性值 s、字长 w 和小数长度 f

示例

T = numerictype(s,w,slope,bias) 创建一个定点 numerictype 对象,该对象具有斜率和偏置定标、有符号属性值 s、字长 w、斜率 slope 和偏置 bias

示例

T = numerictype(s,w,slopeadjustmentfactor,fixedexponent,bias) 创建一个定点 numerictype 对象,该对象具有斜率和偏置定标、有符号属性值 s、字长 w、斜率调整因子 slopeadjustmentfactor、定点指数 fixedexponent 和偏置 bias

示例

T = numerictype(___,PropertyName=Value) 允许您使用名称-值参量设置属性。所有未指定值的属性都被赋予其默认值。

示例

T = numerictype(T1,PropertyName=Value) 允许您在修改任一或所有属性值时创建现有 T 对象 numerictype 的副本 T1

示例

T = numerictype('typename') 创建一个 numerictype 对象,该对象具有与 MATLAB® 或 Simulink® 内置数据类型 typename 相同的数值属性。

示例

T = numerictype(a) 创建一个 numerictype 对象,该对象具有 fi 对象 a 的数值类型属性。

示例

输入参量

全部展开

numerictype 对象的符号性,指定为数值或逻辑值 1 (true) 或 0 (false)。

指定空数组 [] 以自动确定符号性。

示例: T = numerictype(true)

数据类型: logical

存储的整数值的字长(以位为单位),指定为正整数。

示例: T = numerictype(true,16)

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

fi 对象的存储整数值的小数长度,以位为单位,指定为整数标量。小数长度必须为 -65535 ≤ f ≤ 65535 范围内的整数。

示例: T = numerictype(true,16,15)

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

斜率,指定为大于零的有限浮点数。

斜率和偏置确定定点数的定标。

注意

slope=slope adjustment factor×2fixed exponent

更改其中一个属性会影响其他属性。

示例: T = numerictype(true,16,2^-2,4)

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

与对象相关联的偏置,指定为浮点数。

斜率和偏置确定定点数的定标。

示例: T = numerictype(true,16,2^-2,4)

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

斜率调整因子,指定为正标量。

斜率调整因子必须大于或等于 1 且小于 2。如果您输入的 slopeadjustmentfactor 超出此范围,numerictype 对象会自动对 slopeadjustmentfactorfixedexponent 的值应用定标归一化,以便修正后的斜率调整因子大于或等于 1 且小于 2 并保持斜率值。

斜率调整等效于定点数的小数斜率。

注意

slope=slope adjustment factor×2fixed exponent

更改其中一个属性会影响其他属性。

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

与对象相关联的定点指数,指定为整数。

注意

FixedExponent 属性是 FractionLength 的负数。更改一个属性会更改另一个属性。

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

内置数据类型的数据类型名称,指定为字符向量或字符串。使用此输入参量创建一个与指定类型具有相同数据类型和定标属性的 numerictype 对象。

支持以下输入类型:

  • MATLAB 数据类型名称字符串 - 'half''single''double''int8''int16''int32''int64''uint8''uint16''uint32''uint64''logical'

  • Simulink 数据类型名称字符串(非别名)- 'bool''sfix16_En3' 等。

示例: T = numerictype('single')

数据类型: char | string

属性

全部展开

numerictype 对象属性定义定点对象的数据类型和定标特性。numerictype 对象的所有属性都可写。

numerictype 对象的属性在构造 fi 对象时也可以指定为名称-值参量。然而,fi 对象的 numerictype 属性在 fi 对象创建后变为只读。在 fi 对象创建时未指定的 fi 对象的任何 numerictype 属性会自动设置为其默认值。

偏置,指定为浮点数。

斜率和偏置确定定点数的定标。

示例: T = numerictype('DataTypeMode','Fixed-point: slope and bias scaling','Bias',4)

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

数据类型类别,指定为以下值之一:

  • 'Fixed' - 定点或整数数据类型

  • 'Boolean' - 内置 MATLAB 布尔数据类型

  • 'Double' - 内置 MATLAB 双精度数据类型

  • 'ScaledDouble' - 定标双精度数据类型

  • 'Single' - 内置 MATLAB 单精度数据类型

  • 'Half' - MATLAB 半精度数据类型

示例: T = numerictype('Double')

数据类型: char

与对象关联的数据类型和定标模式,指定为以下值之一:

  • 'Fixed-point: binary point scaling' - 由字长和小数长度定义的定点数据类型和定标

  • 'Fixed-point: slope and bias scaling' - 由斜率和偏置定义的定点数据类型和定标

  • 'Fixed-point: unspecified scaling' - 具有未指定的定标的定点数据类型

  • 'Scaled double: binary point scaling' - 保留定点字长和小数长度信息的双精度数据类型

  • 'Scaled double: slope and bias scaling' - 保留定点斜率和偏置信息的双精度数据类型

  • 'Scaled double: unspecified scaling' - 未指定定点定标的双精度数据类型

  • 'Double' - 内置 double

  • 'Single' - 内置 single

  • 'Half' - MATLAB 半精度数据类型

  • 'Boolean' - 内置 boolean

示例: T = numerictype('DataTypeMode','Fixed-point: binary point scaling')

数据类型: char

数据类型覆盖设置,指定为以下值之一:

  • 'Inherit' - 打开 DataTypeOverride

  • 'Off' - 关闭 DataTypeOverride

注意

DataTypeOverride 属性的值设置为默认值 'Inherit' 时,该属性不可见。

示例: T = numerictype('DataTypeOverride','Off')

数据类型: char

与对象相关联的定点指数,指定为整数。

注意

FixedExponent 属性是 FractionLength 的负数。更改一个属性会更改另一个属性。

示例: T = numerictype('FixedExponent',-12)

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

存储的整数值的小数长度(以位为单位),指定为整数。

默认值为基于对象值和字长的最佳精度小数长度。

注意

FractionLength 属性是 FixedExponent 的负数。更改一个属性会更改另一个属性。

示例: T = numerictype('FractionLength',12)

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

对象的定点定标模式,指定为以下值之一:

  • 'BinaryPoint' - numerictype 对象的定标由小数长度定义。

  • 'SlopeBias' - numerictype 对象的定标由斜率和偏置定义。

  • 'Unspecified' - 仅在 numerictype 对象创建时允许的临时设置,它允许自动赋予最佳精度二进制小数点定标。

示例: T = numerictype('Scaling','BinaryPoint')

数据类型: char

对象是否为有符号对象,指定为数值或逻辑值 1 (true) 或 0 (false)。

注意

尽管仍支持 Signed 属性,但 Signedness 属性会始终出现在 numerictype 对象显示中。如果您选择使用 numerictype 属性更改或设置 Signed 对象的符号性,MATLAB 会更新 Signedness 属性的对应值。

示例: T = numerictype('Signed',true)

数据类型: logical

对象是否为有符号对象,指定为以下值之一:

  • 'Signed' - 有符号

  • 'Unsigned' - 无符号

  • 'Auto' - 未指定符号

注意

尽管您可以创建具有未指定符号 (numerictype) 的 Signedness: Auto 对象,但所有定点 numerictype 对象的 Signedness 值都必须为 SignedUnsigned。如果使用 numerictype 对象和 Signedness: Auto 来构造 numerictype 对象,则 Signedness 对象的 numerictype 属性自动默认为 Signed

示例: T = numerictype('Signedness','Signed')

数据类型: char

斜率,指定为有限正浮点数。

斜率和偏置确定定点数的定标。

注意

slope=slope adjustment factor×2fixed exponent

更改其中一个属性会影响其他属性。

示例: T = numerictype('DataTypeMode','Fixed-point: slope and bias scaling','Slope',2^-2)

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

斜率调整因子,指定为正标量。

斜率调整因子必须大于或等于 1 且小于 2。如果您输入的 slopeadjustmentfactor 超出此范围,numerictype 对象会自动对 slopeadjustmentfactorfixedexponent 的值应用定标归一化,以便修正后的斜率调整因子大于或等于 1 且小于 2 并保持斜率值。

斜率调整等效于定点数的小数斜率。

注意

slope=slope adjustment factor×2fixed exponent

更改其中一个属性会影响其他属性。

示例: T = numerictype('DataTypeMode','Fixed-point: slope and bias scaling','SlopeAdjustmentFactor',1.5)

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

存储的整数值的字长(以位为单位),指定为正整数。

示例: T = numerictype('WordLength',16)

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

示例

全部折叠

此示例说明如何使用默认属性设置创建 numerictype 对象。

T = numerictype
T = 
          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 15

此示例说明如何创建一个具有默认字长和定标的有符号或无符号 numerictype 对象。

将符号性参量 s 设置为 1 以创建一个有符号 numerictype 对象。省略字长 w 和小数长度 f 的参量。

T = numerictype(1)
T = 
          DataTypeMode: Fixed-point: unspecified scaling
            Signedness: Signed
            WordLength: 16

对象为有符号对象,字长为 16 位,未指定定标。

通过将符号性参量设置为 0 来创建一个无符号 numerictype 对象。

T = numerictype(0)
T = 
          DataTypeMode: Fixed-point: unspecified scaling
            Signedness: Unsigned
            WordLength: 16

对象的默认字长为 16 位,未指定定标。

此示例说明如何通过省略小数长度参量 f 创建一个具有 32 位字长且未指定定标的 numerictype 对象。

T = numerictype(1,32)
T = 
          DataTypeMode: Fixed-point: unspecified scaling
            Signedness: Signed
            WordLength: 32

对象为有符号对象。

此示例说明如何创建一个有符号 numerictype 对象,该对象具有二进制小数点定标、32 位字长和 30 位小数长度。

T = numerictype(1,32,30)
T = 
          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 32
        FractionLength: 30

此示例说明如何创建一个具有斜率和偏置定标的 numerictype 对象。斜率和偏置定标数的真实值由下式表示:

realworldvalue=(slope×storedinteger)+bias

创建一个 numerictype 对象,该对象描述一种字长为 16 位、斜率为 2^-2、偏置为 4 的有符号定点数据类型。

T = numerictype(1,16,2^-2,4)
T = 
          DataTypeMode: Fixed-point: slope and bias scaling
            Signedness: Signed
            WordLength: 16
                 Slope: 0.25
                  Bias: 4

或者,斜率可以表示为:

slope=slopeadjustmentfactor×2fixedexponent

创建一个 numerictype 对象,该对象描述一个有符号定点数据类型,其字长为 16 位、斜率调整因子为 1、固定指数为 -2、偏置为 4。

T = numerictype(1,16,1,-2,4)
T = 
          DataTypeMode: Fixed-point: slope and bias scaling
            Signedness: Signed
            WordLength: 16
                 Slope: 0.25
                  Bias: 4

此示例说明如何在创建对象时使用名称-值参量来设置 numerictype 属性。

T = numerictype('Signed',true,...
    'DataTypeMode',...
    'Fixed-point: slope and bias scaling', ...
    'WordLength',32,...
    'Slope',2^-2,...
    'Bias',4)
T = 
          DataTypeMode: Fixed-point: slope and bias scaling
            Signedness: Signed
            WordLength: 32
                 Slope: 0.25
                  Bias: 4

此示例说明如何通过使用名称-值参量将 numerictype 属性设置为 Signedness,创建一个具有未指定 SignednessAuto 对象。

T = numerictype('Signedness','Auto')
T = 
          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Auto
            WordLength: 16
        FractionLength: 15

此示例说明如何使用参量和名称-值参量创建一个具有特定数据类型的 numerictype 对象。

T = numerictype(0,24,12,'DataType','ScaledDouble')
T = 
          DataTypeMode: Scaled double: binary point scaling
            Signedness: Unsigned
            WordLength: 24
        FractionLength: 12

返回的 numerictype 对象 T 是无符号对象,其字长为 24 位、小数长度为 12 位、数据类型设置为定标双精度。

此示例说明如何使用内置 MATLAB® 或 Simulink® 数据类型的名称创建一个 numerictype 对象。

创建一个与 MATLAB 数据类型 int8 具有相同数据类型和定标属性的 numerictype 对象。

T = numerictype('int8')
T = 
          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 8
        FractionLength: 0

创建一个与 Simulink 数据类型 sfix16_En3 具有相同数据类型和定标属性的 numerictype 对象。

S = numerictype('sfix16_En3')
S = 
          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 3

此示例说明如何从现有 fi 对象创建 numerictype 对象。

创建一个具有默认属性且未指定值的 fi 对象。

a = fi
a = 

[]

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 15

使用 a 作为输入创建一个 numerictype 对象。

T = numerictype(a)
T = 
          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 15

T 具有与 a 相同的数值类型属性。

扩展功能

全部展开

HDL 代码生成
使用 HDL Coder™ 为 FPGA 和 ASIC 设计生成 VHDL、Verilog 和 SystemVerilog 代码。

版本历史记录

在 R2006a 之前推出

全部展开