| Contents | Index |
| On this page… |
|---|
Inheriting Data Types from Simulink Objects |
The term data type refers to the way computers represent numbers in memory. The type determines the amount of storage allocated to data, the method of encoding a data value as a pattern of binary digits, and the operations available for manipulating the data.
To specify the type of a Stateflow data object:
Open the Data properties dialog box, as described in Opening the Data Properties Dialog Box.
Select the Scope of the data object for which you want to set the data type.
For more information, see Properties You Can Set in the General Pane.
Click the Data Type Assistant button.
Note If you know the specific data type you want to use, you can enter the data type directly in the Type field, or select it from the Type drop-down list, instead of using the Data Type Assistant. For more information, see Working with Data Types in the Simulink documentation. |
Choose a Mode in the Data Type Assistant section of the dialog box.
You can choose from these modes for each scope:
| Scope | Data Type Modes | |||||
|---|---|---|---|---|---|---|
| Inherit | Built in | Fixed point | Enumerated | Expression | Bus Object | |
| Local |
| yes | yes | yes | yes | yes |
| Constant |
| yes | yes | yes | yes | |
| Parameter | yes | yes | yes | yes | yes | yes |
| Input | yes | yes | yes | yes | yes | yes |
| Output | yes | yes | yes | yes | yes | yes |
| Data Store Memory | yes |
|
|
|
| |
Based on the mode you select, specify a data type as follows:
| Mode | What To Specify | |
|---|---|---|
Inherit | You cannot specify a value. You inherit the data type from previously defined data, based on the scope you select for the data object:
| |
Built in | Select a data type from the drop-down list of supported data types, as described in Built-In Data Types. | |
Fixed point | Specify the following information about the fixed-point data:
For information on how to specify these fixed-point data properties, see Fixed-Point Data Properties. | |
Enumerated | Specify the class name for the enumerated data type. For more information, see Using Enumerated Data in Stateflow Charts. | |
Expression | Enter an expression that evaluates to a data type in the Type field. You can use these expressions:
For more information on how to build expressions in the Data properties dialog box, see Entering Expressions and Parameters for Data Properties. | |
Bus object | In the Bus object field, enter the name of a Simulink.Bus object to associate with the Stateflow bus object structure. You must define the bus object in the base workspace. If you have not yet defined a bus object, click Edit to create or edit a bus object in the Bus Editor.
For more information about Stateflow bus object structures, see Working with Structures and Bus Signals in Stateflow Charts. |
Click Apply to save the data type settings.
You can choose from these built-in data types:
Data Type | Description |
|---|---|
double | 64-bit double-precision floating point |
single | 32-bit single-precision floating point |
int32 | 32-bit signed integer |
int16 | 16-bit signed integer |
int8 | 8-bit signed integer |
uint32 | 32-bit unsigned integer |
uint16 | 16-bit unsigned integer |
uint8 | 8-bit unsigned integer |
boolean | Boolean (1 = true; 0 = false) |
ml | Typed internally with the MATLAB array mxArray. The ml data type provides Stateflow data with the benefits of the MATLAB environment, including the ability to assign the Stateflow data object to a MATLAB variable or pass it as an argument to a MATLAB function. See ml Data Type. |
Stateflow data objects of scope Input, Output, Parameter, and Data Store Memory can inherit their data types from Simulink objects, as follows:
| Scope: | Can inherit type from: | |
|---|---|---|
| Input | Simulink input signal connected to corresponding input port in Stateflow chart | |
| Output | Simulink output signal connected to corresponding output
port in Stateflow chart
| |
| Parameter | Corresponding MATLAB workspace variable or Simulink parameter in a masked subsystem | |
| Data Store Memory | Corresponding Simulink data store |
To configure these objects to inherit data types, create the corresponding objects in the Simulink model, and then select Inherit: Same as Simulink from the Type drop-down list in the Data properties dialog box. For more information, see Specifying Data Type and Mode.
To determine the data types that the objects inherit, build the Simulink model and look at the Compiled Type column for each Stateflow data object in the Model Explorer.
You can use the type operator to derive data types from previously defined data. In the following example, the expression type(inbus) specifies the data type of the Stateflow structure counterbus_struct, where inbus is defined by the Simulink.Bus object COUNTERBUS. Therefore, the structure counterbus_struct also derives its data type from the bus object COUNTERBUS.

After you build your model, the Compiled Type column of the Model Explorer shows the type of each data object in the compiled simulation application. For more information, see type Operator.
You can specify the type of Stateflow data by using a Simulink data type alias (see Simulink.AliasType in the Simulink Reference documentation). Suppose that you define a data type alias named MyFloat as follows:
MyFloat = Simulink.AliasType; MyFloat.BaseType = 'single';
In the following example, the data y has the same type as MyFloat.

After you build your model, the Compiled Type column of the Model Explorer shows the type used in the compiled simulation application.
By default, inputs to and outputs from Stateflow charts are of type double. Input signals from Simulink models convert to the type of the corresponding input data objects in Stateflow charts. Likewise, the data output objects convert to double before they are exported as output signals to Simulink models.
To interface directly with signals of data types other than double without the need for conversion, select Use Strong Data Typing with Simulink I/O in the Chart properties dialog box (see Specifying Chart Properties). When you select this check box, the chart accepts input signals of any data type that Simulink supports, as long as the data type of the input signal matches the type of the corresponding Stateflow data object. Otherwise, you receive a type mismatch error.
Note For fixed-point data, select Use Strong Data Typing with Simulink I/O to flag mismatches between input or output fixed-point data in Stateflow charts and their counterparts in Simulink models. |
![]() | Sharing Chart Data with External Modules | Sizing Stateflow Data | ![]() |

Learn how engineers use Stateflow to model state machines in their Simulink models.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |