|On this page…|
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 Open 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 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|
|Data Store Memory|
Based on the mode you select, specify a data type as follows:
|Mode||What To Specify|
You cannot specify a value. You inherit the data type from previously defined data, based on the scope you select for the data object:
Select a data type from the drop-down list of supported data types, as described in Built-In Data Types.
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.
Specify the class name for the enumerated data type. For more information, see Define Enumerated Data in a Chart.
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 Enter Expressions and Parameters for Data Properties.
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.
Click Apply to save the data type settings.
You can choose from these built-in data types:
64-bit double-precision floating point
32-bit single-precision floating point
32-bit signed integer
16-bit signed integer
8-bit signed integer
32-bit unsigned integer
16-bit unsigned integer
8-bit unsigned integer
Boolean (1 = true; 0 = false)
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.
|Scope:||Can inherit type from:|
|Input||Simulink input signal connected to corresponding input port in chart|
|Output||Simulink output signal connected to corresponding output
port in 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 Specify 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 Stateflow 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 charts are of type double. Input signals from Simulink models convert to the type of the corresponding input data objects in 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 Specify 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.