This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Specify Type of Stateflow Data

The term data type refers to how computers represent information in memory. The data 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 by Using the Data Type Assistant

You can specify the type of a data object in either the Property Inspector or the Model Explorer. In the Type field, select a type from the drop-down list or enter an expression that evaluates to a data type. For more information, see Set Data Properties.

Alternatively, use the Data Type Assistant to specify a data Mode and select the data type based on that mode:

  1. In the Model Explorer, on the Data pane, click the Show data type assistant button .

  2. Select a Mode from the drop-down list. The list of available modes depends on the scope of the data object.

    ScopeModes
    LocalInherit (available only in charts that use MATLAB® as the action language), Built in, Fixed point, Enumerated, Bus object, Expression
    ConstantBuilt in, Fixed point, Expression
    ParameterInherit, Built in, Fixed point, Enumerated, Bus object, Expression
    InputInherit, Built in, Fixed point, Enumerated, Bus object, Expression
    OutputInherit, Built in, Fixed point, Enumerated, Bus object, Expression
    Data Store MemoryInherit

  3. Specify additional information based on the mode. The Data Type Assistant populates the Type field based on your specification.

    ModeData Types
    Inherit

    You cannot specify a data type. You inherit the data type based on the scope that you select for the data object:

    For more information, see Inherit Data Types from Simulink Objects.

    Built in

    Specify a data type from the drop-down list of supported data types:

    • 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. ml data cannot have a scope outside the Stateflow hierarchy. That is, it cannot have a scope of Input or Output. For more information, see ml Data Type.

    • string: String. Supported only in charts that use C as the action language. For more information, see Manage Textual Information by Using Strings.

    Fixed point

    Specify this information about the fixed-point data:

    • Signedness: Whether the data is signed or unsigned

    • Word Length: Bit size of the word that holds the quantized integer. Large word sizes represent large values with greater precision than small word sizes. The default value is 16.

    • Scaling: Method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors. The default method is Binary point.

    For information, see Fixed-Point Data Properties.

    Enumerated

    Specify the class name for the enumerated data type. For more information, see Define Enumerated Data Types.

    Bus object

    Specify the name of a Simulink.Bus object to associate with the Stateflow® bus object structure. Click Edit to create or edit a bus object in the Bus Editor. You can also inherit bus object properties from Simulink signals.

    Expression

    Specify an expression that evaluates to a data type. You can use one of these expressions:

    For more information, see Enter Expressions and Parameters for Data Properties.

  4. To save the data type settings, click Apply.

The Data Type Assistant is available only through the Model Explorer.

Inherit Data Types from Simulink Objects

When you select Inherit: Same as Simulink from the Type drop-down list, data objects of scope Input, Output, Parameter, and Data Store Memory inherit their data types from Simulink objects.

ScopeDescription
InputInherits type from the Simulink input signal connected to corresponding input port in chart.
Output

Inherits type from the Simulink output signal connected to corresponding output port in chart.

Avoid inheriting data types from output signals. Values that back-propagate from Simulink blocks can be unpredictable.

ParameterInherits type from the corresponding MATLAB base workspace variable or Simulink parameter in a masked subsystem.
Data Store MemoryInherits type from the corresponding Simulink data store.

To determine the data types that the objects inherit:

  1. Build the Simulink model.

  2. Open the Model Explorer.

  3. In the Contents pane, examine the CompiledType column.

Derive Data Types from Other Data Objects

You can use the type operator to derive data types from other Stateflow data objects:

type(data_obj)
For example, in the model sf_bus_demo, the expression type(inbus) returns the data type of the input structure inbus. Because inbus derives its type from the Simulink.Bus object COUNTERBUS, the data type of the local structure counterbus_struct also derives its data type from COUNTERBUS.

After you build your model, the CompiledType column of the Model Explorer shows the type used in the compiled simulation application.

Specify Data Types by Using a Simulink Alias

You can specify the type of Stateflow data by using a Simulink data type alias. For more information, see Simulink.AliasType.

For example, suppose that you want to define a data type alias MyFloat that corresponds to the built-in data type single. At the MATLAB command prompt, enter:

MyFloat = Simulink.AliasType;
MyFloat.BaseType = 'single';

To use this alias to specify the type of a data object, select the object in the Property Inspector or the Model Explorer. In the Type field, enter the alias name MyFloat.

After you build your model, the CompiledType column of the Model Explorer shows the type used in the compiled simulation application.

Strong Data Typing with Simulink Inputs and Outputs

By default, the Use Strong Data Typing with Simulink I/O chart property allows C charts to interface directly with signals from Simulink models. The chart accepts only input signals whose data type matches the type of the corresponding Stateflow data object. Otherwise, a type mismatch error occurs. For example, by selecting Use Strong Data Typing with Simulink I/O, you can flag mismatches between input or output fixed-point data in charts and their counterparts in Simulink models. For more information, see Specify Properties for Stateflow Charts.

If you clear the Use Strong Data Typing with Simulink I/O chart property, the chart converts inputs signals of type double to the type of the corresponding input data object in the chart. The chart converts output data objects to type double before exporting them as output signals to Simulink models.

Note

The Use Strong Data Typing with Simulink I/O chart property is provided for backward compatibility. Clearing this check box can produce unpredictable results and is not recommended.

Related Topics