Main Content

Stateflow.State

State in chart, state, or box

    Description

    Use Stateflow.State objects to describe an operating mode of a reactive system. For more information, see Represent Operating Modes by Using States.

    Creation

    Description

    example

    state = Stateflow.State(parent) creates a Stateflow.State object in a parent chart, state, or box.

    Input Arguments

    expand all

    Parent for the new state, specified as a Stateflow® API object of one of these types:

    Properties

    expand all

    Stateflow API objects have properties that correspond to the values you set in the Stateflow Editor. To access or modify a property, use dot notation. To access or modify multiple properties for multiple API objects, use the get and set functions, respectively. For more information, see Modify Properties and Call Functions of Stateflow Objects.

    Content

    Name of the state, specified as a character vector.

    Label for the state, specified as a character vector. For more information, see Specify Labels in States and Transitions Programmatically.

    This property is read-only.

    State during action, specified as a character vector. The value of this property depends on the LabelString property for the state. For more information, see Specify Labels in States and Transitions Programmatically. This property is not supported in Moore charts.

    This property is read-only.

    State entry action, specified as a character vector. The value of this property depends on the LabelString property for the state. For more information, see Specify Labels in States and Transitions Programmatically. This property is not supported in Moore charts.

    This property is read-only.

    State exit action, specified as a character vector. The value of this property depends on the LabelString property for the state. For more information, see Specify Labels in States and Transitions Programmatically. This property is not supported in Moore charts.

    This property is read-only.

    State action in a Moore chart, specified as a character vector. The value of this property depends on the LabelString property for the state. For more information, see Specify Labels in States and Transitions Programmatically. This property is supported only in Moore charts. For more information, see Design Rules for Moore Charts.

    This property is read-only.

    State on actions, specified as a cell array of character vectors in the form

    {'trigger1','action1',...,'triggerN','actionN'}

    The value of this property depends on the LabelString property for the state. For more information, see Specify Labels in States and Transitions Programmatically. This property is not supported in Moore charts.

    Whether to comment out the state, specified as a numeric or logical 1 (true) or 0 (false). Setting this property to true is equivalent to right-clicking the state and selecting Comment Out. For more information, see Commenting Stateflow Objects in a Chart.

    This property is read-only.

    Whether the state is implicitly commented out, specified as a numeric or logical 1 (true) or 0 (false). The state is implicitly commented out when you comment out a state or box that contains it.

    Comment text added to the state, specified as a character vector. This property applies only when the IsExplicitlyCommented property is true. In the Stateflow Editor, when you point to the comment badge on the state, the text appears as a tooltip. When you set the IsExplicitlyCommented property to false, the value of CommentText reverts to ''.

    Graphical Appearance

    Position and size of the state, specified as a four-element numeric vector of the form [left top width height].

    This property is read-only.

    Whether the state graphically intersects a box, state, or function, specified as a numeric or logical 1 (true) or 0 (false).

    Whether the state is a grouped state, specified as a numeric or logical 1 (true) or 0 (false). When you copy and paste a grouped state, you copy not only the state but all of its contents. For more information, see Copy and Paste by Grouping.

    Whether the state is a subchart, specified as a numeric or logical 1 (true) or 0 (false).

    Whether to display a preview of the state contents, specified as a numeric or logical 1 (true) or 0 (false). This property applies only when the IsSubchart property is true.

    Size of incoming transition arrows, specified as a scalar.

    Font size for the state label, specified as a scalar. The StateFont.Size property of the chart that contains the state sets the initial value of this property.

    State Decomposition

    Decomposition of substates at the top level of containment in the state, specified as 'EXCLUSIVE_OR' or 'PARALLEL_AND'. For more information, see Specify Substate Decomposition.

    This property is read-only.

    Decomposition of sibling states, specified as 'OR' or 'AND'. The state inherits this property from the Decomposition property of its parent state or chart.

    Execution order for the state in parallel (AND) decomposition, specified as an integer scalar. This property applies only when both of these conditions are satisfied:

    • The Type property of the state is 'AND'.

    • The UserSpecifiedStateTransitionExecutionOrder property of the chart that contains the state is true.

    Active State Output

    Whether to create an active state data output port for the state, specified as a numeric or logical 1 (true) or 0 (false). For more information, see Monitor State Activity Through Active State Data.

    This property is read-only.

    Active state data object for the state, specified as a Stateflow.Data object. This property applies only when the HasOutputData property for the state is true.

    Name of the active state data object for the state, specified as a character vector. This property applies only when the HasOutputData property for the state is true.

    Monitoring mode for the active state output data, specified as 'SelfActivity', 'ChildActivity', or 'LeafStateActivity'.

    Name of the enumerated data type for the active state data object for the state, specified as a character vector. This property applies only when the OutputMonitoringMode property for the state is 'ChildActivity' or 'LeafStateActivity'. For more information, see Enum Name.

    Whether to define the enumerated data type for the active state data output manually, specified as a numeric or logical 1 (true) or 0 (false). This property applies only when the OutputMonitoringMode property for the state is 'ChildActivity' or 'LeafStateActivity'. For more information, see Define State Activity Enumeration Type.

    Signal Logging

    Signal logging properties for the state, specified as a Stateflow.SigLoggingInfo object with these properties:

    • DataLogging — Whether to enable signal logging, specified as a numeric or logical 1 (true) or 0 (false).

    • DecimateData — Whether to limit the amount of logged data, specified as a numeric or logical 1 (true) or 0 (false).

    • Decimation — Decimation interval, specified as an integer scalar. This property applies only when the DecimateData property is true.

    • LimitDataPoints — Whether to limit the number of data points to log, specified as a numeric or logical 1 (true) or 0 (false).

    • MaxPoints — Maximum number of data points to log, specified as an integer scalar. This property applies only when the LimitDataPoints property is true.

    • NameMode — Source of the signal name, specified as 'SignalName' or 'Custom'.

    • LoggingName — Custom signal name, specified as a character vector. This property applies only when the NameMode property is 'Custom'.

    For more information, see Log Simulation Output for States and Data.

    Example: state.LoggingInfo.DataLogging = true;

    Debugging

    Debugger properties for the state, specified as a Stateflow.StateDebug object with these properties:

    • OnEntry — Whether to set the On State Entry breakpoint, specified as a numeric or logical 1 (true) or 0 (false).

    • OnDuring — Whether to set the During State breakpoint, specified as a numeric or logical 1 (true) or 0 (false).

    • OnExit — Whether to set the On State Exit breakpoint, specified as a numeric or logical 1 (true) or 0 (false).

    For more information, see Set Breakpoints to Debug Charts.

    Example: state.Debug.Breakpoints.OnEntry = true;

    Example: state.Debug.Breakpoints.OnDuring = true;

    Example: state.Debug.Breakpoints.OnExit = true;

    Whether to set the state as a test point, specified as a numeric or logical 1 (true) or 0 (false). For more information, see Monitor Test Points in Stateflow Charts.

    Code Generation

    Appearance of the state functions in generated code, specified as one of these values:

    • 'Auto' — An internal calculation determines the appearance of state functions in generated code.

    • 'Function' — State functions are implemented as separate C functions.

    • 'Inline' — Calls to state functions are replaced by code.

    For more information, see Inline State Functions in Generated Code (Simulink Coder).

    Hierarchy

    This property is read-only.

    Chart that contains the state, specified as a Stateflow.Chart object.

    This property is read-only.

    Subviewer for the state, specified as a Stateflow.Chart, Stateflow.State, or Stateflow.Box object. The subviewer is the chart or subchart where you can graphically view the state.

    This property is read-only.

    Machine that contains the state, specified as a Stateflow.Machine object.

    This property is read-only.

    Location of the parent of the state in the model hierarchy, specified as a character vector.

    Identification

    Description for the state, specified as a character vector.

    Document link for the state, specified as a character vector.

    User-defined tag for the state, specified as data of any type.

    This property is read-only.

    Session-independent identifier, specified as an integer scalar. Use this property to distinguish the state from other objects in the model.

    This property is read-only.

    Unique identifier, specified as an integer scalar. Unlike SSIdNumber, the value of this property is reassigned every time you start a new MATLAB® session and may be recycled after an object is deleted.

    Object Functions

    findIdentify specified objects in hierarchy
    getChildrenIdentify children of object
    getParentIdentify parent of object
    defaultTransitionsIdentify default transitions in specified object
    innerTransitionsIdentify inner transitions with specified source
    outerTransitionsIdentify outer transitions with specified source
    sinkedTransitionsIdentify transitions with specified destination
    sourcedTransitionsIdentify transitions with specified source
    dialogOpen properties dialog box
    isCommentedDetermine if graphical object is commented out
    viewDisplay object in editing environment
    highlightHighlight graphical object
    fitToViewZoom in on graphical object

    Examples

    collapse all

    Add a state in the chart ch. Set its name to 'A'.

    state = Stateflow.State(ch);
    state.Name = 'A';

    To enter a multiline label in the state state, you can:

    • Call the MATLAB function sprintf and use the escape sequence \n to insert newline characters:

      str = sprintf('A\nen: action1();\ndu: action2();\nen,du: action3();');
      state.LabelString = str;
    • Enter a concatenated text expression that uses the integer 10 as the ASCII equivalent of a newline character:

      str = ['A',10, ...
          'en: action1();',10, ...
          'du: action2();',10, ...
          'en,du: action3();'];
      state.LabelString = str;

    State with entry and during actions.

    To extract the state name, entry action, and during action specified by the state label, enter:

    name = state.Name
    name =
    
        'A'
    entry = state.EntryAction
    entry =
    
        ' action1();
          action3();'
    during = state.DuringAction
    during =
    
        ' action2();
          action3();'

    For more information, see Specify Labels in States and Transitions Programmatically.

    Create a supertransition that connects junction j1, which is inside a subchart, to junction j2, which is outside the subchart.

    Stateflow chart with one state. A transition connects a junction inside the state to a junction outside the state.

    Save the original position of subchart st to a temporary workspace variable subchartPosition.

    subchartPosition = st.Position;

    Convert the subchart to a normal state by setting its IsSubchart and IsGrouped properties to false.

    st.IsSubchart = false;
    st.IsGrouped = false;

    When you convert a subchart to a normal state, it may change size to display its contents.

    Stateflow chart with one state. A transition connects a junction inside the state to a junction outside the state.

    Add a transition that connects junction j1 to junction j2 in the chart ch.

    tr = Stateflow.Transition(ch);
    tr.Source = j1;
    tr.Destination = j2;

    Stateflow chart with one subchart. A supertransition connects a junction inside the subchart to a junction outside the subchart.

    Revert the state to a subchart by setting its IsSubchart property to true. Restore the subchart to its original position.

    st.IsSubchart = true;
    st.Position = subchartPosition;

    The state A is now a subchart and the transition between the junctions is now a supertransition.

    Stateflow chart with one subchart. A supertransition connects a junction inside the subchart to a junction outside the subchart.

    For more information, see Move Between Levels of Hierarchy by Using Supertransitions.

    Introduced before R2006a