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. Simulink® 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 Simulink Coder™ 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
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 Guidelines). In that way, you can avoid introducing data type errors that prevent your model from running to completion or simulating at all.
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, Simulink 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
Whenever you start a simulation, enable display of port data types, or refresh the port data type display, Simulink 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.
You can insert typecasting (data type conversion) blocks in your model to resolve type conflicts. For more information, see Data Type Conversion.