Documentation Center

  • Trial Software
  • Product Updates

Type Stateflow Data

What Is Data Type?

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.

Specify Data Type and Mode

To specify the type of a Stateflow® data object:

  1. Open the Data properties dialog box, as described in Open the Data Properties Dialog Box.

  2. 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.

  3. 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.

  4. Choose a Mode in the Data Type Assistant section of the dialog box.

    You can choose from these modes for each scope:

    ScopeData Type Modes
     InheritBuilt inFixed pointEnumeratedExpressionBus 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

  5. Based on the mode you select, specify a data type as follows:

    ModeWhat 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:

    • Whether the data is signed or unsigned

    • Word length

    • Scaling mode

    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 Define Enumerated Data in a Chart.

    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 Enter 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.

      Note:   You can also inherit bus object properties from Simulink signals.

  6. Click Apply to save the data type settings.

Built-In Data Types

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.

    Note:   ml data cannot have a scope outside the Stateflow hierarchy; that is, it cannot have a scope of Input to Simulink or Output to Simulink.

Inherit Data Types from Simulink Objects

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:
InputSimulink input signal connected to corresponding input port in chart
OutputSimulink output signal connected to corresponding output port in chart
ParameterCorresponding MATLAB workspace variable or Simulink parameter in a masked subsystem
Data Store MemoryCorresponding 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.

Derive Data Types from Previously Defined Data

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.

Type Data by Using an Alias

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.

Strong Data Typing with Simulink I/O

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.

    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 charts and their counterparts in Simulink models.

Was this topic helpful?