| Simulink® | ![]() |
| On this page… |
|---|
Data Types Supported by Simulink® Block Support for Data and Numeric Signal Types Creating Signals of a Specific Data Type |
The term data type refers to the way in which a computer represents numbers in memory. A data type determines the amount of storage allocated to a number, the method used to encode the number's value as a pattern of binary digits, and the operations available for manipulating the type. Most computers provide a choice of data types for representing numbers, each with specific advantages in the areas of precision, dynamic range, performance, and memory usage. To optimize performance, you can specify the data types of variables used in the MATLAB® technical computing environment. The Simulink® software builds on this capability by allowing you to specify the data types of Simulink signals and block parameters.
The ability to specify the data types of a model's signals and block parameters is particularly useful in real-time control applications. For example, it allows a Simulink model to specify the optimal data types to use to represent signals and block parameters in code generated from a model by automatic code-generation tools, such as the Real-Time Workshop® product. By choosing the most appropriate data types for your model's signals and parameters, you can dramatically increase performance and decrease the size of the code generated from the model.
Simulink performs extensive checking before and during a simulation to ensure that your model is typesafe, that is, that code generated from the model will not overflow or underflow and thus produce incorrect results. Simulink models that use the default data type (double) are inherently typesafe. Thus, if you never plan to generate code from your model or use a nondefault data type in your models, you can skip the remainder of this section.
On the other hand, if you plan to generate code from your models and use nondefault data types, read the remainder of this section carefully, especially the section on data type rules (see Data Typing Rules). In that way, you can avoid introducing data type errors that prevent your model from running to completion or simulating at all.
Simulink supports all built-in MATLAB data types except int64 and uint64. The term built-in data type refers to data types defined by MATLAB itself as opposed to data types defined by MATLAB users. Unless otherwise specified, the term data type in the Simulink documentation refers to built-in data types. The following table lists the built-in MATLAB data types supported by Simulink.
| Name | Description |
|---|---|
double | Double-precision floating point |
single | Single-precision floating point |
int8 | Signed 8-bit integer |
uint8 | Unsigned 8-bit integer |
int16 | Signed 16-bit integer |
uint16 | Unsigned 16-bit integer |
int32 | Signed 32-bit integer |
uint32 | Unsigned 32-bit integer |
Besides the built-in types, Simulink defines a boolean (1 or 0) type, instances of which are represented internally by uint8 values.
Many Simulink blocks also support fixed-point data types. See Blocks — Alphabetical List in the online documentation for information on the data types supported by specific blocks for parameter and input and output values. If the documentation for a block does not specify a data type, the block inputs or outputs only data of type double.
To view a table that summarizes the data types supported by the blocks in the Simulink block libraries, execute the following command at the MATLAB command line:
showblockdatatypetable
The Simulink software allows you to create models that use fixed-point numbers to represent signals and parameter values. Use of fixed-point data can reduce the memory requirements and increase the speed of code generated from a model.
To execute a model that uses fixed-point numbers, you must have the Simulink® Fixed Point™ product installed on your system. Specifically, you must have the product to:
Update a Simulink diagram (Ctrl+D) containing fixed-point data types
Run a model containing fixed-point data types
Generate code from a model containing fixed-point data types
Log the minimum and maximum values produced by a simulation
Automatically scale the output of a model using the autoscaling tool
If the Simulink Fixed Point product is not installed on your system, you can execute a fixed-point model as a floating-point model by enabling automatic conversion of fixed-point data to floating-point data during simulation. See Overriding Fixed-Point Specifications for details.
If you do not have the Simulink Fixed Point product installed and do not enable automatic conversion of fixed-point to floating-point data, an error occurs if you try to execute a fixed-point model.
Note You do not need the Simulink Fixed Point product to edit a model containing fixed-point blocks, or to use the Data Type Assistant to specify fixed-point data types, as described in Specifying a Fixed-Point Data Type . |
Most of the functionality in the Fixed-Point Tool is for use with the Simulink Fixed Point product. However, even if you do not have the Simulink Fixed Point product, you can use the tool's data type override mode to simulate a model that specifies fixed-point data types.
Data type override mode allows you to share fixed-point models with people in your company who do not have the Simulink Fixed Point product. In data type override mode, the fixed-point values are replaced with floating-point values when executing the model. Such replacement does not affect Fixed-Point Toolbox™ fi objects used as fixed-point parameters in your model. However, you can prevent the checkout of a Fixed-Point Toolbox license by setting the fipref DataTypeOverride property to TrueDoubles (see the Fixed-Point Toolbox documentation).
To simulate a model in data type override mode:
From the Simulink Tools menu, select Fixed-Point > Fixed-Point Tool.
The Fixed-Point Tool appears.
Set the Data type override parameter to either True doubles or True singles.
All Simulink blocks accept signals of type double by default. Some blocks prefer boolean input and others support multiple data types on their inputs. See Simulink Blocks in Simulink® Reference for information on the data types supported by specific blocks for parameter and input and output values. If the documentation for a block does not specify a data type, the block inputs or outputs only data of type double.
You can introduce a signal of a specific data type into a model in any of the following ways:
Load signal data of the desired type from the MATLAB workspace into your model via a root-level Inport block or a From Workspace block.
Create a Constant block in your model and set its parameter to the desired type.
Use a Data Type Conversion block to convert a signal to the desired data type.
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:
A rule that inherits a data type (see Data Type Inheritance Rules)
The name of a built-in data type (see Built-In Data Types)
An expression that evaluates to a data type (see Data Type Expressions)
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® Reference.
Data Type Inheritance Rules. 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.
| Inheritance Rule | Description |
|---|---|
| Inherit: Inherit via back propagation | 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. |
| Inherit: Same as input | The block uses the data type of its sole input signal for its output signal. |
| Inherit: Same as first input | The block uses the data type of its first input signal for its output signal. |
| Inherit: Same as second input | The block uses the data type of its second input signal for its output signal. |
| Inherit: Inherit via internal rule | The block uses an internal rule to determine its output data type. The internal rule chooses a data type that optimizes the accuracy and precision of the block output signal. |
Built-In Data Types. You can specify the value of a data type parameter as the name of a built-in data type, for example, single or boolean. 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.
Data Type Expressions. 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:
fixdt Command
Specify the value of a data type parameter as a command that invokes the fixdt function. This function allows you to create a Simulink.NumericType 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 Simulink.NumericType and Simulink.AliasType, simplify the task of making model-wide changes to output data types and allow you to use custom aliases for data types. See Working with Data Objects for more information about Simulink data objects.
Using the Model Explorer (see The Model Explorer), you can assign the same output data type to multiple blocks simultaneously. For example, the sldemo_f14 model that comes with the Simulink product contains numerous Gain blocks. Suppose you want to specify the Output data type parameter of all the Gain blocks in the model as single. You can achieve this task as follows:
Use the Model Explorer search bar (see Search Bar) to identify all blocks in the sldemo_f14 model of type Gain.
The Model Explorer Contents pane lists all Gain blocks in the model.

In the Model Explorer Contents pane, select all the Gain blocks whose Output data type parameter you want to specify.
Model Explorer highlights the rows corresponding to your selections.

In the Model Explorer Contents pane, click the data type associated with one of the selected Gain blocks.
Model Explorer displays a pull-down menu with valid data type options.

In the pull-down menu, enter or select the desired data type, for example, single.
Model Explorer specifies the data type of all selected items as single.

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 |
|---|---|
Inherit | Inheritance rules for data types |
Built in | Built-in data types |
Fixed point | Fixed-point data types |
Expression | Expressions that evaluate to data types |
Bus Object | Simulink.Bus object name, valid only for the Embedded MATLAB™ Function block and the Stateflow® Chart block |
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. See Specifying Fixed-Point Data Types with the Data Type Assistant in the Simulink® Fixed Point™ User's Guide for details about specifying fixed-point data types.
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 a detailed discussion about fixed-point data, see Fixed-Point Concepts in the Simulink® Fixed Point™ User's Guide. 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:
Sign. 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.
Word length. 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 32. The default bit size is 16.
Scaling. 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 in the Simulink® Fixed Point™ User's Guide.
Calculate Best-Precision Scaling. 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. The Simulink software displays the scaling values in the Fraction Length field or the Slope and Bias fields. For more information, see Constant Scaling for Best Precision in the Simulink® Fixed Point™ User's Guide.
Lock output scaling against changes by the autoscaling tool. Check this box to prevent a Simulink model from replacing the current fixed-point type with a type that the autoscaling tool chooses. See Automatic Scaling in the Simulink® Fixed Point™ User's Guide for instructions on autoscaling fixed-point data.
Showing Fixed-Point Details. 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 Checking Signal Ranges and Checking Parameter Values 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. See Fixed-Point Concepts in the Simulink® Fixed Point™ User's Guide for information about these three quantities.
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's Signal Attributes tab, the subpane could look like this:

Note that 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.
Note also that Initial condition displays the value 1..4. The actual value is a vector or matrix whose smallest element is 1 and largest element is 4. To conserve space, the Fixed-point details subpane shows only the smallest and largest element of a vector or matrix. An ellipsis (..) replaces the omitted values. The underlying definition of the vector or matrix is unaffected.
To display the data types of ports in your model, select Port Data Types from the Simulink Format menu. The port data type display is not updated when you change the data type of a diagram element. To refresh the display, press Ctrl+D.
Whenever you start a simulation, enable display of port data types, or refresh the port data type display, the Simulink software performs a processing step called data type propagation. This step involves determining the types of signals whose type is not otherwise specified and checking the types of signals and input ports to ensure that they do not conflict. If type conflicts arise, an error dialog is displayed that specifies the signal and port whose data types conflict. The signal path that creates the type conflict is also highlighted.
Note You can insert typecasting (data type conversion) blocks in your model to resolve type conflicts. See Typecasting Signals for more information. |
Observing the following rules can help you to create models that are typesafe and, therefore, execute without error:
Signal data types generally do not affect parameter data types, and vice versa.
A significant exception to this rule is the Constant block, whose output data type is determined by the data type of its parameter.
If the output of a block is a function of an input and a parameter, and the input and parameter differ in type, the Simulink software converts the parameter to the input type before computing the output.
In general, a block outputs the data type that appears at its inputs.
Significant exceptions include Constant blocks and Data Type Conversion blocks, whose output data types are determined by block parameters.
Virtual blocks accept signals of any type on their inputs.
Examples of virtual blocks include Mux and Demux blocks and unconditionally executed subsystems.
The elements of a signal array connected to a port of a nonvirtual block must be of the same data type.
The signals connected to the input data ports of a nonvirtual block cannot differ in type.
Control ports (for example, Enable and Trigger ports) accept any data type.
Solver blocks accept only double signals.
Connecting a non-double signal to a block disables zero-crossing detection for that block.
An error is displayed whenever it detects that a signal is connected to a block that does not accept the signal's data type. If you want to create such a connection, you must explicitly typecast (convert) the signal to a type that the block does accept. You can use the Data Type Conversion block to perform such conversions.
![]() | Working with Data | Working with Data Objects | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |