The Data Type Assistant is an interactive graphical tool that simplifies the task of specifying data types for blocks and data objects. The assistant appears on block and object dialog boxes, adjacent to parameters that provide data type control, such as the Output data type parameter. For example, it appears on the Signal Attributes pane of the Constant block dialog box shown here.
You can selectively show or hide the Data Type Assistant by clicking the applicable button:
Click the Show data type assistant button
to display the assistant.
Click the Hide data type assistant button
to hide a visible assistant.
Use the Data Type Assistant to specify a data type as follows:
In the Mode field, select the category of data type that you want to specify. In general, the options include the following:
Mode | Description |
---|---|
| Inheritance rules for data types |
| Built-in data types |
| Fixed-point data types |
| Enumerated data types |
| Bus object data types |
| Expressions that evaluate to data types |
The assistant changes dynamically to display different options
that correspond to the selected mode. For example, setting Mode to Expression
causes
the Constant block dialog box to appear as follows.
In the field that is to the right of the Mode field, select or enter a data type.
For example, suppose that you designate the variable myDataType
as
an alias for a single
data type. You create an
instance of the Simulink.AliasType
class
and set its BaseType
property by entering the following
commands:
myDataType = Simulink.AliasType
myDataType.BaseType = 'single'
You can use this data type object to specify the output data
type of a Constant block. Enter the data type alias name, myDataType
,
as the value of the expression in the assistant.
Click the OK or Apply button to apply your changes.
The assistant uses the data type that you specified to populate the associated data type parameter in the block or object dialog box. In the following example, the Output data type parameter of the Constant block specifies the same expression that you entered using the assistant.
For more information about the data types that you can specify using the Data Type Assistant, see Entering Valid Data Type Values. For details about specifying fixed-point data types, see Specify Fixed-Point Data Types with the Data Type Assistant (Fixed-Point Designer).
When the Data Type Assistant Mode is Fixed
point
, the Data Type Assistant displays fields for specifying
information about your fixed-point data type. For example, the next figure shows the
Block Parameters dialog box for a Gain block, with the Signal
Attributes tab selected and a fixed-point data type specified.
If the Scaling is Slope
and bias
rather than Binary point
,
the Data Type Assistant displays a Slope field
and a Bias field rather than a Fraction length field:
You can use the Data Type Assistant to set these fixed-point properties:
Specify whether you want the fixed-point data to be Signed
or Unsigned
.
Signed data can represent positive and negative values, but unsigned
data represents positive values only. The default setting is Signed
.
Specify the bit size of the word that will hold the quantized integer. Large word sizes represent large values with greater precision than small word sizes. Word length can be any integer between 0 and 128. The default bit size is 16.
Specify the method for scaling your fixed-point data to avoid
overflow conditions and minimize quantization errors. The default
method is Binary point
scaling. You can
select one of two scaling modes:
Scaling Mode | Description |
---|---|
Binary point | If you select this mode, the Data Type Assistant displays the Fraction Length field, which specifies the binary point location. Binary points can be positive or negative integers. A positive integer moves the binary point left of the rightmost bit by that amount. For example, an entry of 2 sets the binary point in front of the second bit from the right. A negative integer moves the binary point further right of the rightmost bit by that amount, as in this example: The default binary point is 0. |
Slope and bias | If you select this mode, the Data Type Assistant displays fields for entering the Slope and Bias. Slope can be any positive real number, and the default slope is 1.0. Bias can be any real number, and the default bias is 0.0. You can enter slope and bias as expressions that contain parameters you define in the MATLAB® workspace. |
Note
Use binary-point scaling whenever possible to simplify the implementation of fixed-point data in generated code. Operations with fixed-point data using binary-point scaling are performed with simple bit shifts and eliminate expensive code implementations, which are required for separate slope and bias values.
For more information about fixed-point scaling, see Scaling (Fixed-Point Designer).
When the Mode is Built in
or
Fixed point
, you can use the Data type
override option to specify whether you want this data type to
inherit or ignore the data type override setting specified for its context, that
is, for the block, Simulink.Signal
object or Stateflow® chart in Simulink® that is using the signal. The default behavior is
Inherit
.
Data Type Override Mode | Description |
---|---|
Inherit (default) |
Inherits the data type override setting from its
context, that is, from the block,
|
Off |
Ignores the data type override setting of its context and uses the fixed-point data type specified for the signal. |
The ability to turn off data type override for an individual data type provides greater control over the data types in your model when you apply data type override. For example, you can use this option to ensure that data types meet the requirements of downstream blocks regardless of the data type override setting.
Click this button to calculate best-precision values for both Binary
point
and Slope and bias
scaling,
based on the specified minimum and maximum values. Simulink displays the scaling values in the Fraction
Length field or the Slope and
Bias fields. For more information, see Constant Scaling for Best Precision (Fixed-Point Designer).
When you specify a fixed-point data type, you can use the Fixed-point details subpane to see information about the fixed-point data type that is currently displayed in the Data Type Assistant. To see the subpane, click the expander next to Fixed-point details in the Data Type Assistant. The Fixed-point details subpane appears at the bottom of the Data Type Assistant:
The rows labeled Output minimum
and Output
maximum
show the same values that appear in the corresponding Output minimum and Output
maximum fields above the Data Type Assistant. The names
of these fields may differ from those shown. For example, a fixed-point
block parameter would show Parameter minimum and Parameter maximum, and the corresponding Fixed-point details rows would be labeled accordingly.
See Specify Signal Ranges and Specify Minimum and Maximum Values for Block Parameters for
more information.
The rows labeled Representable minimum
, Representable maximum
, and Precision
always appear. These rows show the minimum value, maximum value, and precision
that can be represented by the fixed-point data type currently displayed in the
Data Type Assistant.
The values displayed by the Fixed-point details subpane do not automatically update if you click Calculate Best-Precision Scaling, or change the range limits, the values that define the fixed-point data type, or anything elsewhere in the model. To update the values shown in the Fixed-point details subpane, click Refresh Details. The Data Type Assistant then updates or recalculates all values and displays the results.
Clicking Refresh Details does
not change anything in the model, it only changes the display. Click OK or Apply to
put the displayed values into effect. If the value of a field cannot
be known without first compiling the model, the Fixed-point
details subpane shows the value as Unknown
.
If any errors occur when you click Refresh Details, the Fixed-point details subpane shows an error flag on the left of the applicable row, and a description of the error on the right. For example, the next figure shows two errors:
The row labeled Output minimum
shows the error Cannot evaluate
because
evaluating the expression MySymbol
, specified in
the Output minimum field, did not
return an appropriate numeric value. When an expression does not evaluate
successfully, the Fixed-point details subpane
displays the unevaluated expression (truncating to 10 characters if
necessary to save space) in place of the unavailable value.
To correct the error in this case, you would need to define MySymbol
in
an accessible workspace to provide an appropriate numeric value. After
you clicked Refresh Details, the
value of MySymbol
would appear in place of its
unevaluated text, and the error indicator and error description would
disappear.
To correct the error shown for Output maximum
,
you would need to decrease Output maximum,
increase Word length, or decrease Fraction length (or some combination of these
changes) sufficiently to allow the fixed-point data type to represent
the maximum value that it could have.
Other values relevant to a particular block can also appear in the Fixed-point details subpane. For example, on a Discrete-Time Integrator block Signal Attributes tab, the subpane can look like this:
The values displayed for Upper saturation limit and Lower saturation limit are greyed out. This appearance indicates that the corresponding parameters are not currently used by the block. The greyed-out values can be ignored.
To conserve space, Initial condition displays the smallest value and the largest value in the vector or matrix, using ellipsis to represent the other values. The underlying definition of the vector or matrix is unaffected.
Select this check box to prevent replacement of the current data type with a type that the Fixed-Point Tool or Fixed-Point Advisor chooses. For instructions on autoscaling fixed-point data, see Scaling (Fixed-Point Designer).
You can specify an enumerated data type by selecting the Enum:
<class name>
option and specify an enumerated
object.
In the Data Type Assistant, you can use
the Mode parameter to specify a bus as a data
object for a block. Select the Enumerated
option
and specify an enumerated object.
For details about enumerated data types, see Data Types.
The blocks listed in the section called Data Types for Bus Signals support your specifying a bus object as a data
type. For those blocks, in the Data type parameter,
select the Bus: <object name>
option
and specify a bus object. You cannot use the Expression
option
to specify a bus object as a data type for a block.
In the Data Type Assistant, you can use
the Mode parameter to specify a bus as a data
object for a block. Select the Bus
option
and specify a bus object.
You can specify a bus object as the data type for data objects such as
Simulink.Signal
, Simulink.Parameter
, and
Simulink.BusElement
. In the Model Explorer, in Properties
dialog box for a data object, in the Data type parameter,
select the Bus: <object name>
option and specify a
bus object. You can also use the Expression
option to
specify a bus object.
For more information on specifying a bus object data type, see Specify Bus Properties with Simulink.Bus Objects.