To control the data type of a signal in a Simulink® model, you specify a data type for the corresponding block output.
You can also introduce a new signal of a specific data type into a model in any of the following ways:
Simulink blocks determine the data type of their outputs by default. Many blocks allow you to override the default type and explicitly specify an output data type, using a block parameter that is typically named Output data type. For example, the Output data type parameter appears on the Signal Attributes pane of the Constant block dialog box.
See the following topics for more information:
|For Information About...||See...|
Valid data type values that you can specify
An assistant that helps you specify valid data type values
Specifying valid data type values for multiple blocks simultaneously
In general, you can specify the output data type as any of the following:
Valid data type values vary among blocks. You can use the pull-down menu associated with a block data type parameter to view the data types that a particular block supports. For example, the Data type pull-down menu on the Data Store Memory block dialog box lists the data types that it supports, as shown here.
For more information about the data types that a specific block supports, see the documentation for the block in the Simulink documentation.
Blocks can inherit data types from a variety of sources, including signals to which they are connected and particular block parameters. You can specify the value of a data type parameter as a rule that determines how the output signal inherits its data type. To view the inheritance rules that a block supports, use the data type pull-down menu on the block dialog box. The following table lists typical rules that you can select.
Simulink automatically determines the output data type of the block during data type propagation (see Data Type Propagation). In this case, the block uses the data type of a downstream block or signal object.
The block uses the data type of its sole input signal for its output signal.
The block uses the data type of its first input signal for its output signal.
The block uses the data type of its second input signal for its output signal.
The block uses an internal rule to determine its output data type. The internal rule chooses a data type that optimizes numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware. It is not always possible for the software to optimize efficiency and numerical accuracy at the same time.
When you apply inherited data types to a signal, Simulink determines the specific data type of the signal only after you update the block diagram.
To display this specific data type on the block diagram, see Port Data Types.
To inspect this specific data type for multiple signals in a searchable, sortable table, use the Model Data Editor (on the Modeling tab, click Model Data Editor). The right side of the Data Type column shows the specific data type for each signal. For more information about the Model Data Editor, see Configure Data Properties by Using the Model Data Editor.
You can specify the value of a data type parameter as the name
of a built-in data type, for example,
To view the built-in data types that a block supports, use the data
type pull-down menu on the block dialog box. See Data Types Supported by Simulink for
a list of all built-in data types that are supported.
You can specify the value of a data type parameter as an expression that evaluates to a numeric data type object. Simply enter the expression in the data type field on the block dialog box. In general, enter one of the following expressions:
Specify the value of a data type parameter as a command that invokes the
fixdt function. This
function allows you to create a
object that describes a fixed-point or floating-point data type.
Data Type Object Name
Specify the value of a data type parameter as the name of a data object that represents a data
type. Simulink data objects that you instantiate from classes, such as
simplify the task of making model-wide changes to output data types and
allow you to use custom aliases for data types. See Data Objects for more
information about Simulink data objects.
Using the Model Data Editor (see Configure Data Properties by Using the Model Data Editor), you can assign the same data type to multiple signals simultaneously. You can use this technique to design the interface of your model by configuring data types and other attributes of multiple Inport and Outport blocks at once (see Configure Data Interface for Component). You can also finely control the data types of arbitrary signals in your block algorithm.
For example, the
slexAircraftExample model that comes with the
Simulink product contains numerous Gain blocks. Suppose you want
to specify the output data type of the three Gain blocks at the root level of the
single. You can achieve this task as follows:
In the Model Data Editor (on the Modeling tab, click Model Data Editor), inspect the Signals tab.
Next to the Filter contents box, toggle the Filter using selection button.
At the top level of the model, select the signal lines that represent the
outputs of the three Gain blocks (labeled
Mq). The Model Data Editor shows three rows that
correspond to the three signals.
In the Model Data Editor, select all three signals (rows). For example, you can press Ctrl+A or hold Shift while clicking the top and bottom rows in the Source column.
For any of the three signals, click the cell in the Data
Type column. From the drop-down list, select
single. The Model Data Editor applies this
selection to all of the selected rows.
To convert a model to a strict single precision design, see Validate a Floating-Point Embedded Model.
In some cases, you cannot rely on data type inheritance (see Data Type Inheritance Rules) to establish equivalence between the data
types of different data items (such as signal lines in parallel data paths or bus
elements in a
Simulink.Bus object). Instead, you
can create a
Simulink.AliasType object in a workspace or data
Simulink.NumericType object if you
do not want to rename the shared data type by creating an alias. Set
IsAlias property to
This example shows how to use a
to share an output data type between two lookup table blocks in the
Open the example model
The model creates
in the base workspace. One of the objects is named
At the command prompt, inspect the properties of
s16En15 = NumericType with properties: DataTypeMode: 'Single' IsAlias: 0 DataScope: 'Auto' HeaderFile: '' Description: ''
This object represents the built-in Simulink data type
In the model, navigate into the
On the Modeling tab, click Model Data Editor. In the Model Data Editor, inspect the Signals tab.
In the model, click the output signal of the Pumping Constant block. The Model
Data Editor Data Type column shows that the signal
data type is set to
Click the output signal of the Ramp Rate Ki block. The output data type of this
block is also set to
Update the block diagram and, if necessary, expand the width of the Data
Type column. The right side of the column shows that the
two lookup table blocks use the data type
At the command prompt, configure
represent the data type
s16En15.DataTypeMode = 'Double';
Update the block diagram.
The output signals of the two lookup table blocks now use the
double. Due to data type inheritance,
other signals, such as
acquire the same data type.
Alternatively, to establish data type equivalence between algorithms or data paths in the same model, you can use blocks such as Data Type Propagation and Data Type Conversion Inherited. When you use these blocks, you do not need to create and permanently store a data type object. However, you cannot use the blocks to share a data type between signals in different models unless the models are in the same model reference hierarchy.
In a model, you can create signals that conform to custom C data types, such as structures, that your existing C code defines. Use these signals to:
Replace existing C code with a Simulink model.
Integrate C code for simulation in Simulink (for example, by using the Legacy Code Tool).
Prepare to generate code (Simulink Coder™) that you can integrate with existing code.
Use these techniques to match your custom data types:
For a structure type, create a
Use the object as the data type for bus signals. See Data Types for Bus Signals.
For an enumeration, create an enumeration class and use it as the data type for signals. See Use Enumerated Data in Simulink Models.
To match a
typedef statement that
represents an alias of a primitive, numeric data type, use a
as the data type for signals. See
To create these classes and objects, you can use the function
If a MATLAB Function block or Stateflow® chart in your model uses an imported enumeration or structure type,
configure the model configuration parameters to include
#include) the type definition from your external header file.
See Control Imported Bus and Enumeration Type Definitions (for a MATLAB Function block)
and Access Custom Code Variables and Functions in Stateflow Charts (Stateflow) and Integrate Custom Structures in Stateflow Charts (Stateflow) (for a chart).
When a signal uses an inherited data type setting such as
Inherit: Inherit via
internal rule (the default setting for most blocks), to determine
the meaningful data type that the signal uses for simulation, update the block
diagram and then use one or both of these techniques:
In the Simulink Editor, on the Debug tab, select Information Overlays > Port Data Type. The data types appear on the block diagram next to each signal. For more information, see Port Data Types.
Inspect the right side of the Data Type column in the Model Data Editor (on the Modeling tab, click Model Data Editor). For more information about the Model Data Editor, see Configure Data Properties by Using the Model Data Editor.
Using these techniques to inspect data types helps you to:
Design the data type strategy for a model on a high level.
Debug numerical issues due to quantization and overflows.
Make a model more easily understood when sharing it.
For more information, see Port Data Types.
doubleDespite Changing Settings
If many of the data items (signals, parameters, and states)
in your model continue to use the data type
you configure block parameters such as Output data type,
confirm that the model is not configured to override data types. See Control Data Type Override.