| Contents | Index |
| On this page… |
|---|
Data Types Supported by Simulink Block Support for Data and Numeric Signal Types Creating Signals of a Specific Data Type Specifying Block Output Data Types |
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 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 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.
Several blocks support bus objects (Simulink.Bus) as data types. See Bus Objects.
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 software. However, even if you do not have Simulink Fixed Point software, you can configure data type override settings to simulate a model that specifies fixed-point data types. In this mode, the Simulink software temporarily overrides fixed-point data types with floating-point data types when simulating the model.
Note If you use fi objects or embedded numeric data types in your model or workspace, you might introduce fixed-point data types into your model. You can set fipref to prevent the checkout of a Fixed-Point Toolbox license. For more information, see Licensing in the Fixed-Point Toolbox documentation. |
To simulate a model without using Simulink Fixed Point:
In the Model Hierarchy pane, select the root model.
From the Simulink model Tools menu, select Fixed-Point Tool.
The Fixed-Point Tool opens.
In the Current system settings panel:
If you use fi objects or embedded numeric data types in your model, set the fipref DataTypeOverride property to TrueDoubles or TrueSingles (to be consistent with the model-wide data type override setting) and the DataTypeOverrideAppliesTo property to All numeric types.
For example, at the MATLAB command line, enter:
p = fipref('DataTypeOverride', 'TrueDoubles', ...
'DataTypeOverrideAppliesTo', 'AllNumericTypes');An enumeration is a user-defined data type with a fixed set of names that represent a single type of value. When the data type of an entity is an enumeration, the value of the entity must be one of the values defined that enumeration. For information about enumerations, see Enumerations and Modeling. Do not confuse enumerations with enumerated property types (see Enumerated Property Types).
A bus object (Simulink.Bus) specifies the architectural properties of a bus, as distinct from the values of the signals it contains. For example, a bus object can specify the number of elements in a bus, the order of those elements, whether and how elements are nested, and the data types of constituent signals; but not the signal values.
You can specify a bus object as a data type for the following blocks:
You can specify a bus object as a data type for the following classes:
See Specifying a Bus Object Data Type for information about how to specify a bus object as a data type for blocks and classes.
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: Overview), 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 The Model Explorer: 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 |
Enumerated | Enumerated data types |
Bus object | Bus object data types |
Expression | 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. 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:
Signedness. 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.
Data type override. 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, Simulink.Signal object or Stateflow chart in Simulink that is using the signal. |
| 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.
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.
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 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.
Lock output data type setting against changes by the fixed-point tools. 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. See Scaling in the Simulink Fixed Point User's Guide for instructions on autoscaling fixed-point data.
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 Enumerations and Modeling.
The blocks listed in the section called Bus Objects 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 Associating Bus Objects with Simulink Blocks
To display the data types of ports in your model, select Format > Port/Signal Displays > Port Data Types. The port data type display is not automatically 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.
You can use data type override mode to switch the data types in your model. This capability allows you to maintain one model but simulate and generate code for multiple data types, and also validate the numerical behavior for each type. For example, if you implement an algorithm using double-precision data types and want to check whether the algorithm is also suitable for single-precision use, you can apply a data type override to floating-point data types to replace all doubles with singles without affecting any other data types in your model.
To apply a data type override, you must specify the data type that you want to apply and the data type that you want to replace.
You can set a data type override using one of the following methods. In these examples, both methods change all floating-point data types to single.
From the Command Line. For example:
set_param(gcs, 'DataTypeOverride', 'Single'); set_param(gcs, 'DataTypeOverrideAppliesTo','Floating-point');
Using the Fixed-Point Tool. For example:
From the model menu, select Tools > Fixed-Point Tool.
The Fixed-Point Tool opens.
If you cannot see the Current system settings panel on the right side of the Fixed-Point Tool dialog box, from the Fixed-Point Tool View menu, select Show Current System Settings.
In the Fixed-Point Tool Current system settings panel, set:
Data type override to Single.
Data type override applies to Floating-point.
For more information on data type override settings, see fxptdlg.
This tutorial uses the ex_single_validation model to show how you can use data type overrides. It proves that an algorithm, which implements double-precision data types, is also suitable for single-precision embedded use.

The inputs In2 and In3 are double-precision inputs to the Sum and Product blocks.
The outputs of the Sum and Product blocks are data inputs to the Multiport Switch block.
The input In1 is the control input to the Multiport Switch block. The value of this control input determines which of its other inputs, the sum of In2 and In3 or the product of In2 and In3, passes to the output port. Because In1 is a control input, its data type is int8.
The Relational Operator block compares the output of the Multiport Switch block to In4, and outputs a Boolean signal.
In this tutorial, you follow these steps:
Generate Code for the Double-Precision Model
First generate code for the double-precision model to act as a reference against which you compare the code generated for the single-precision model.
Convert the Model to Single Precision
Use the Fixed-Point Tool to convert all floating-point data types in the model to singles. When you apply the data type override, you do not want to affect the data type of the integer input In1, which acts as a control input. Changing the data type of In1 might change the behavior of the system. Applying the data type override only to floating-point data types ensures that integer data types are not overridden. Similarly, you do not want to override the logical Boolean output of the Relational Operator block. Data type overrides never apply to Boolean data types, so this output data type remains unchanged.
Generate Code for the Single-Precision Model
Finally, you generate code for this single-precision model and verify that this code is suitable for single-precision embedded use.
Open the ex_single_validation model.
Generate Code for the Double-Precision Model.
From the model menu, select Simulation > Configuration Parameters.
The Configuration Parameters dialog box opens.
In the left pane, under Code Generation, select Report.
On the Report pane, verify that Create code generation report and Launch report automatically are selected so that the Simulink Coder software creates a code generation report.
From the Simulink model menu, select Tools > Code Generation > Build Model.
Simulink Coder generates code and displays the code generation report.
Examine the generated code.
In the left pane of the report, click the ex_single_validation.h link.
The report displays the header file in the right pane.
In the code that defines external inputs and outputs for root inports and outports, the input In1 has the type int8_T, all the remaining inputs are double-precision real_T, and the output Out1 is boolean_T.
/* External inputs (root inport signals with auto storage) */
typedef struct {
int8_T In1;
real_T In2;
real_T In3;
real_T In4;
} ExternalInputs_ex_single_valida;
typedef struct {
boolean_T Out1;
} ExternalOutputs_ex_single_valid;
In the left pane of the report, click the ex_single_validation.c link.
The report displays the C code in the right pane. The code for the double-precision model contains only double-precision operations.
real_T rtb_MultiportSwitch;
if (ex_single_validation_U.In1 == 1) {
rtb_MultiportSwitch = ex_single_validation_U.In2 +
ex_single_validation_U.In3;
} else {
rtb_MultiportSwitch = ex_single_validation_U.In2 *
ex_single_validation_U.In3;
}
ex_single_validation_Y.Out1 = (rtb_MultiportSwitch <=
ex_single_validation_U.In4);Convert the Model to Single Precision.
From the model menu, select Tools > Fixed-Point Tool.
The Fixed-Point Tool opens.
If you cannot see the Settings for selected system panel on the right side of the Fixed-Point Tool dialog box, from the Fixed-Point Tool View menu, select Show Settings for Selected System.
In the Fixed-Point Tool Settings for selected system panel:
Set the Data type override parameter to Single.
Set the Data type override applies to parameter to Floating-point.
Click Apply.
From the Fixed-Point Tool menu, select Simulation > Start.
The simulation runs. The data type override replaces all the floating-point (double) data types in the model with single data types, but does not affect the integer or Boolean data types.

Generate Code for the Single-Precision Model.
From the model menu, select Tools > Code Generation > Build Model.
Simulink Coder generates code and displays the code generation report.
Examine the generated code.
In the left pane of the report, click the ex_single_validation.h link.
The report displays the header file in the right pane.
In the code that defines external inputs, the inputs In2, In3, and In4 are now single-precision real32_T, whereas In1 is still int8_T, and Out1 is still boolean_T.
/* External inputs (root inport signals with auto storage) */
typedef struct {
int8_T In1;
real32_T In2;
real32_T In3;
real32_T In4;
} ExternalInputs_ex_single_valida;
typedef struct {
boolean_T Out1;
} ExternalOutputs_ex_single_valid;In the left pane of the report, click the ex_single_validation.c link.
The report displays the C code in the right pane.
real32_T rtb_MultiportSwitch;
if (ex_single_validation_U.In1 == 1) {
rtb_MultiportSwitch = ex_single_validation_U.In2 +
ex_single_validation_U.In3;
} else {
rtb_MultiportSwitch = ex_single_validation_U.In2 *
ex_single_validation_U.In3;
}
ex_single_validation_Y.Out1 = (rtb_MultiportSwitch <=
ex_single_validation_U.In4);
The code for the single-precision model contains only single-precision operations. Therefore, this code is suitable for single-precision embedded use.
![]() | Working with Data | Working with Data Objects | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |