Main Content

Specify Scope and Type of Stateflow Data

Scope and type specifications define how data objects behave in your Stateflow charts.

Scope determines where data originates and how it connects to your chart environment. For example, input data flows from Stateflow® into the chart, while local data remains internal to chart operations.

Type specifies the data format and storage characteristics, affecting memory usage, numerical precision, and available operations. For example, you might use double for high-precision calculations or uint8 for memory-efficient integer storage.

Proper data specification affects three critical aspects of chart performance.

  • Storage efficiency, or the amount of memory allocated for data objects.

  • Data representation, or how values convert to binary patterns for processing.

  • Available operations, or the set of allowed mathematical and logical operations.

Specify Data Types

You can define data types using the Property Inspector:

  1. Select the data object in the Symbols pane.

  2. In the Type field, choose from:

    • Drop-down list of built-in types

    • Custom expression that evaluates to a valid data type

    • Inheritance option to derive type from Simulink objects

For comprehensive information about data property configuration, see "Set Data Properties."

Inherit Data Types from Simulink Objects

To derive data types from connected Simulink objects, set the Type drop-down to Inherit: Same as Simulink. This option applies to specific data scopes:

ScopeType Source
InputSimulink® input signal connected to the corresponding chart input port
OutputSimulink output signal connected to the corresponding chart output port
ParameterMATLAB base workspace variable, Simulink data dictionary entry, or masked subsystem parameter
Data Store MemorySimulink data store with matching name

Do not use Inherit: Same as Simulink when you require a specific data type.

To verify inherited data types:

  1. Build the Simulink model to compile data type information.

  2. Open the Model Explorer and navigate to your chart.

  3. In the Contents pane, examine the CompiledType column to see the actual inherited types.

Derive Data Types from Other Data Objects

Use the type operator to base the type of one data object on another Stateflow data object. Using type helps you maintain type consistency across related data.

The model sf_bus_demo defines a local structure using this expression:

type(inbus)

This expression makes counterbus_struct inherit the same data type as the input structure inbus. Since inbus derives its type from the Simulink.Bus object COUNTERBUS, the local structure also uses the COUNTERBUS type definition.

For detailed implementation examples, see Integrate Custom Structures in Stateflow Charts.

Specify Data Types Using Simulink Aliases

You can create reusable data type definitions with Simulink alias types. Aliases allow you to be consistent in type naming across your model.

To create and use a data type alias:

  1. Define the alias at the MATLAB command prompt:

    MyFloat = Simulink.AliasType;
    MyFloat.BaseType = "single";
  2. In your Stateflow chart, select the target data object in the Symbols pane.

  3. In the Property Inspector, set Type to MyFloat.

  4. Build your model to compile the type information.

  5. Verify the compiled type in the Model Explorer CompiledType column.

The alias provides a descriptive name and maintains the underlying base type properties for code generation and simulation.

See Also

(Simulink) | (Simulink) | (Simulink)

Topics