Construct an embedded.numerictype
object describing fixed-point
or floating-point data type
T = numerictype
creates a default numerictype
object.
T = numerictype(
creates a fixed-point
s
)numerictype
object with unspecified scaling, a signed property value of
s
, and a 16-bit word length.
T = numerictype(
creates a fixed-point s
,w
,slopeadjustmentfactor
,fixedexponent
,bias
)numerictype
object with slope and bias scaling, a
signed property value of s
, word length of w
,
slopeadjustmentfactor
, and bias
.
T = numerictype(___,
allows you to set properties using name-value pairs. All properties that you do not specify
a value for are assigned their default values.Name,Value
)
T = numerictype(T1,
allows you to
make a copy, Name,Value
)T1
, of an existing numerictype
object,
T
, while modifying any or all of the property values.
T = numerictype('Double')
creates a numerictype
object of data type double.
T = numerictype('Single')
creates a numerictype
object of data type single.
T = numerictype('Boolean')
creates a numerictype
object of data type Boolean.
numerictype
ObjectThis example shows how to create a numerictype
object with default property settings.
T = numerictype
T = DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 15
numerictype
Object with Default Word Length and ScalingThis example shows how to create a numerictype
object with the default word length and scaling by omitting the arguments for word length, w
, and fraction length, f
.
T = numerictype(1)
T = DataTypeMode: Fixed-point: unspecified scaling Signedness: Signed WordLength: 16
The object is signed, with a word length of 16 bits and unspecified scaling.
You can use the signedness argument, s
, to create an unsigned numerictype
object.
T = numerictype(0)
T = DataTypeMode: Fixed-point: unspecified scaling Signedness: Unsigned WordLength: 16
The object is has the default word length of 16 bits and unspecified scaling.
numerictype
Object with Unspecified ScalingThis example shows how to create a numerictype
object with unspecified scaling by omitting the fraction length argument, f
.
T = numerictype(1,32)
T = DataTypeMode: Fixed-point: unspecified scaling Signedness: Signed WordLength: 32
The object is signed, with a 32-bit word length.
numerictype
Object with Specified Word and Fraction LengthThis example shows how to create a signed numerictype
object with binary-point scaling, a 32-bit word length, and 30-bit fraction length.
T = numerictype(1,32,30)
T = DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 32 FractionLength: 30
numerictype
Object with Slope and Bias ScalingThis example shows how to create a numerictype
object with slope and bias scaling. The real-world value of a slope and bias scaled number is represented by:
Create a numerictype
object that describes a signed, fixed-point data type with a word length of 16 bits, a slope of 2^-2, and a bias of 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
Alternatively, the slope can be represented by:
Create a numerictype
object that describes a signed, fixed-point data type with a word length of 16 bits, a slope adjustment factor of 1, a fixed exponent of -2, and a bias of 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
Object with Specified Property ValuesThis example shows how to use name-value pairs to set numerictype
properties at object creation.
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
Object with Unspecified SignThis example shows how to create a numerictype
object with an unspecified sign by using name-value pairs to set the Signedness
property to Auto
.
T = numerictype('Signedness','Auto')
T = DataTypeMode: Fixed-point: binary point scaling Signedness: Auto WordLength: 16 FractionLength: 15
numerictype
Object with Specified Data TypeThis example shows how to create a numerictype
object with a specific data type by using arguments and name-value pairs.
T = numerictype(0,24,12,'DataType','ScaledDouble')
T = DataTypeMode: Scaled double: binary point scaling Signedness: Unsigned WordLength: 24 FractionLength: 12
The returned numerictype
object, T
, is unsigned, and has a word length of 24 bits, a fraction length of 12 bits, and a data type set to scaled double.
numerictype
ObjectThis example shows how to create a numerictype
object with data type set to single, double, or Boolean at object creation.
Create a numerictype
object with the data type mode set to single.
T = numerictype('Single')
T = DataTypeMode: Single
Create a numerictype
object with the data type mode set to double.
T = numerictype('Double')
T = DataTypeMode: Double
Create a numerictype
object with the data type mode set to Boolean.
T = numerictype('Boolean')
T = DataTypeMode: Boolean
s
— Whether object is signedtrue
or 1
(default) | false
or 0
Whether the object is signed, specified as a numeric or logical 1
(true
) or 0
(false
).
Example: T = numerictype(true)
Data Types: logical
w
— Word length16
(default) | positive integerWord length, in bits, of the stored integer value, specified as a positive integer.
Example: T = numerictype(true,16)
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
f
— Fraction length15
(default) | integerFraction length, in bits, of the stored integer value, specified as an integer.
Fraction length can be greater than word length. For more information, see Binary Point Interpretation (Fixed-Point Designer).
Example: T = numerictype(true,16,15)
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
slope
— Slope3.0518e-05
(default) | finite floating-point number greater than zeroSlope, specified as a finite floating-point number greater than zero.
The slope and the bias determine the scaling of a fixed-point number.
Note
Changing one of these properties affects the others.
Example: T = numerictype(true,16,2^-2,4)
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
bias
— Bias associated with object0
(default) | floating-point numberBias associated with the object, specified as a floating-point number.
The slope and the bias determine the scaling of a fixed-point number.
Example: T = numerictype(true,16,2^-2,4)
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
slopeadjustmentfactor
— Slope adjustment factor1
(default) | positive scalarSlope adjustment factor, specified as a positive scalar.
The slope adjustment factor must be greater than or equal to 1 and less than 2. If
you input a slopeadjustmentfactor
outside this range, the
numerictype
object automatically applies a scaling normalization to
the values of slopeadjustmentfactor
and
fixedexponent
so that the revised slope adjustment factor is
greater than or equal to 1 and less than 2, and maintains the value of the slope.
The slope adjustment is equivalent to the fractional slope of a fixed-point number.
Note
Changing one of these properties affects the others.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
fixedexponent
— Fixed-point exponent-15
(default) | integerFixed-point exponent associated with the object, specified as an integer.
Note
The FixedExponent
property is the negative of the
FractionLength
. Changing one property changes the other.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
F = numerictype('DataTypeMode','Fixed-point: binary point
scaling','DataTypeOverride','Inherit')
Note
When you create a numerictype
object by using name-value pairs,
Fixed-Point Designer™ creates a default numerictype
object, and then, for each
property name you specify in the constructor, assigns the corresponding value. This
behavior differs from the behavior that occurs when you use a syntax such as T =
numerictype(s,w)
. See Example: Construct a numerictype Object with Property Name and Property Value Pairs.
'Bias'
— Bias0
(default) | floating-point numberBias, specified as a floating-point number.
The slope and bias determine the scaling of a fixed-point number.
Example: T = numerictype('DataTypeMode','Fixed-point: slope and bias
scaling','Bias',4)
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
'DataType'
— Data type category'Fixed'
(default) | 'Boolean'
| 'Double'
| 'ScaledDouble'
| 'Single'
Data type category, specified as one of these values:
'Fixed'
– Fixed-point or integer data type
'Boolean'
– Built-in MATLAB® Boolean data type
'Double'
– Built-in MATLAB double data type
'ScaledDouble'
– Scaled double data type
'Single'
– Built-in MATLAB single data type
Example: T = numerictype('Double')
Data Types: char
'DataTypeMode'
— Data type and scaling mode'Fixed-point: binary point scaling'
(default) | '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'
| 'Single'
| 'Boolean'
Data type and scaling mode associated with the object, specified as one of these values:
'Fixed-point: binary point scaling'
– Fixed-point data type
and scaling defined by the word length and fraction length
'Fixed-point: slope and bias scaling'
– Fixed-point data
type and scaling defined by the slope and bias
'Fixed-point: unspecified scaling'
– Fixed-point data type
with unspecified scaling
'Scaled double: binary point scaling'
– Double data type
with fixed-point word length and fraction length information retained
'Scaled double: slope and bias scaling'
– Double data type
with fixed-point slope and bias information retained
'Scaled double: unspecified scaling'
– Double data type
with unspecified fixed-point scaling
'Double'
– Built-in double
'Single'
– Built-in single
'Boolean'
– Built-in boolean
Example: T = numerictype('DataTypeMode','Fixed-point: binary point
scaling')
Data Types: char
'DataTypeOverride'
— Data type override settingsData type override settings, specified as one of these values:
'Inherit'
– Turn on
DataTypeOverride
'Off'
– Turn off DataTypeOverride
Note
The DataTypeOverride
property is not visible when its value
is set to the default, 'Inherit'
.
Example: T =
numerictype('DataTypeOverride','Off')
Data Types: char
'FixedExponent'
— Fixed-point exponent-15
(default) | integerFixed-point exponent associated with the object, specified as an integer.
Note
The FixedExponent
property is the negative of the
FractionLength
. Changing one property changes the other.
Example: T = numerictype('FixedExponent',-12)
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
'FractionLength'
— Fraction length of the stored integer valueFraction length, in bits, of the stored integer value, specified as an integer.
The default value is the best precision fraction length based on the value of the object and the word length.
Example: T = numerictype('FractionLength',12)
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
'Scaling'
— Fixed-point scaling mode'BinaryPoint'
(default) | 'SlopeBias'
| 'Unspecified'
Fixed-point scaling mode of the object, specified as one of these values:
'BinaryPoint'
– Scaling for the
numerictype
object is defined by the fraction
length.
'SlopeBias'
– Scaling for the
numerictype
object is defined by the slope and bias.
'Unspecified'
– Temporary setting that is only allowed at
numerictype
object creation, and allows for the automatic
assignment of a best-precision binary point scaling.
Example: T = numerictype('Scaling','BinaryPoint')
Data Types: char
'Signed'
— Whether the object is signedtrue
or 1
(default) | false
or 0
Whether the object is signed, specified as a numeric or logical
1
(true
) or 0
(false
).
Note
Although the Signed
property is still supported, the
Signedness
property always appears in the
numerictype
object display. If you choose to change or set the
signedness of your numerictype
object using the
Signed
property, MATLAB updates the corresponding value of the Signedness
property.
Example: T = numerictype('Signed',true)
Data Types: logical
'Signedness'
— Whether the object is signed'Signed'
(default) | 'Unsigned'
| 'Auto'
Whether the object is signed, specified as one of these values:
'Signed'
– Signed
'Unsigned'
– Unsigned
'Auto'
– Unspecified sign
Note
Although you can create numerictype
objects with an
unspecified sign (Signedness: Auto
), all fixed-point
numerictype
objects must have a Signedness
of Signed
or Unsigned
. If you use a
numerictype
object with Signedness: Auto
to
construct a numerictype
object, the Signedness
property of the numerictype
object automatically defaults to
Signed
.
Example: T = numerictype('Signedness','Signed')
Data Types: char
'Slope'
— Slope3.0518e-05
(default) | finite, positive floating-point numberSlope, specified as a finite, positive floating-point number.
The slope and bias determine the scaling of a fixed-point number.
Note
Changing one of these properties affects the others.
Example: T = numerictype('DataTypeMode','Fixed-point: slope and bias
scaling','Slope',2^-2)
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
'SlopeAdjustmentFactor'
— Slope adjustment factor1
(default) | positive scalarSlope adjustment factor, specified as a positive scalar.
The slope adjustment factor must be greater than or equal to 1 and less than 2. If
you input a slopeadjustmentfactor
outside this range, the
numerictype
object automatically applies a scaling normalization
to the values of slopeadjustmentfactor
and
fixedexponent
so that the revised slope adjustment factor is
greater than or equal to 1 and less than 2, and maintains the value of the
slope.
The slope adjustment is equivalent to the fractional slope of a fixed-point number.
Note
Changing one of these properties affects the others.
Example: T = numerictype('DataTypeMode','Fixed-point: slope and bias
scaling','SlopeAdjustmentFactor',1.5)
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
'WordLength'
— Word length of the stored integer value16
(default) | positive integerWord length, in bits, of the stored integer value, specified as a positive integer.
Example: T = numerictype('WordLength',16)
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Usage notes and limitations:
Fixed-point signals coming in to a MATLAB Function block from Simulink® are assigned a numerictype
object that is populated
with the signal's data type and scaling information.
Returns the data type when the input is a non fixed-point signal.
Use to create numerictype
objects in generated code.
All
numerictype
object properties related to the data type must be
constant.
You have a modified version of this example. Do you want to open this example with your edits?