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

Specifying Data Type and Mode

To specify the type of a Stateflow® data object:

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

  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 Show data type assistant button .

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

    You can choose from these modes for each scope:

    ScopeData Type Modes
     InheritBuilt inFixed pointExpressionBus Object
    Local

    yes

    yes

    yes

    yes

    Constant

    yes

    yes

    yes

    Parameter

    yes

    yes

    yes

    yes

    Input

    yes

    yes

    yes

    yes

    yes

    Output

    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.

    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, 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 Types Editor.

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

    For more information about Stateflow bus object structures, see Working with Structures and Bus Signals in Stateflow® Charts.

  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.

Inheriting 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 Stateflow chart
OutputSimulink output signal connected to corresponding output port in Stateflow 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. 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.

Deriving 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 Stateflow operator type(x) specifies the data type of the Stateflow local data object y, where x is a local data object of type int32. After you build your model, the Compiled Type column of the Model Explorer displays the type of each data object in the compiled simulation application.

Typing 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). After you build your model, the Compiled Type column of the Model Explorer displays the type used in the compiled simulation application. In the following example, you use the alias MyFloat, with BaseType set to single, to type the Stateflow local data y.

Strong Data Typing with Simulink® I/O

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, enable the option Use Strong Data Typing with Simulink I/O for the Stateflow chart (see Specifying Chart Properties). When you enable this option, the Stateflow chart accepts input signals of any data type that Simulink models support, provided that the type of the input signal matches the type of the corresponding Stateflow input data object. Otherwise, you receive a type mismatch error.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS