Stateflow Editor Operations

Stateflow Editor

Use the Stateflow® Editor to draw, zoom, modify, print, and save a chart shown in the window.

Opening a Stateflow chart displays the chart in the Stateflow Editor.

To open a new Stateflow chart in the Stateflow Editor:

  1. At the MATLAB® command prompt, enter:

    CommandResult
    sfnew
    Creates a chart with the default action language. For more information, see sfnew.
    sfnew -matlab
    Creates an empty chart with MATLAB as the action language.
    sfnew -C
    Creates an empty C chart.
    stateflow
    Creates an empty chart with the default action language and displays the Stateflow block library.

    The Simulink® Editor opens, with an empty chart.

  2. Double-click the chart object.

    The Stateflow Editor opens.

The Stateflow Editor window includes the following sections:

  • Title bar

    The full chart name appears here in model name/chart name* format. The * character appears on the end of the chart name for a newly created chart or for an existing chart that has been edited but not saved yet.

  • Toolstrip

    Most editor commands are available from the toolstrip. You can identify each tool of the toolbar by placing your pointer over it until an identifying tool tip appears.

  • Object palette

    Displays a set of tools for drawing states, transitions, and other chart objects. To add an object, you can use the palette to:

    • Click the icon for the object and move the cursor to the spot in the drawing area where you want to place the object.

    • Drag the icon for the object into the drawing area.

    • Double-click the icon and then click multiple times in the drawing area to make copies of the object.

  • Explorer bar

    The breadcrumb shows the systems that you have open in the editor. Click a system in the breadcrumb to display that system. The e also contains buttons for navigating the chart hierarchy (see Navigate Subcharts).

  • Model Browser

    Click the double arrows in the bottom left corner to open or close a tree-structured view of the model in the editor.

  • Drawing area — This area displays an editable copy of a chart.

  • Context menus (shortcut menus) — These menus pop up from the drawing area when you right-click an object. They display commands that apply only to that object. If you right-click an empty area of the chart, the context menu applies to the chart object.

  • Status information — Near the top of the editor, you can see (and reset) the simulation time and the simulation mode. The bottom status bar displays the status of the Stateflow processing, tool tips, the zoom factor, and the solver.

Undo and Redo Editor Operations

You can undo and redo operations that you perform in a chart. When you undo an operation, you reverse the last edit operation that you performed. After you undo operations in the chart, you can also redo them one at a time.

  • To undo an operation in the chart, press Ctrl + Z.

  • To redo an operation in the chart, press Ctrl + Y.

You can undo and redo many operations you complete on Stateflow objects in the Symbols pane or the Property Inspector.

Exceptions for Undo

You can undo or redo all editor operations, with the following exceptions:

  • You cannot undo the operation of turning subcharting off for a state previously subcharted.

    To understand subcharting, see Encapsulate Modal Logic by Using Subcharts.

  • You cannot undo the drawing of a supertransition or the splitting of an existing transition.

    Splitting of an existing transition refers to the redirection of the source or destination of a transition segment that is part of a supertransition. For a description of supertransitions, see Draw a Supertransition Into a Subchartand Draw a Supertransition Out of a Subchart.

  • You cannot undo any changes made to the chart using the Stateflow API.

    For a description of the Stateflow API, see Stateflow Programmatic Interface.

    Note

    When you perform one of the preceding operations, the undo and redo buttons are disabled from undoing and redoing any prior operations.

Specify Colors and Fonts in a Chart

You can change the way Stateflow displays an individual element of a chart or specify the global display options used throughout the entire chart.

Change Size of a Single Element

To change the display size for a single element in the chart, right-click the element, and then select a new Format option from the context menu. The options available depend on the element that you select.

OptionStatesTransitionsJunctionsAnnotationsOther Elements
Font SizeAvailableAvailableNot AvailableAvailableAvailable
Arrowhead SizeAvailableAvailableAvailableNot AvailableNot Available
Junction SizeNot AvailableNot AvailableAvailableNot AvailableNot Available
Font StyleNot AvailableNot AvailableNot AvailableAvailableNot Available
ShadowNot AvailableNot AvailableNot AvailableAvailableNot Available
Text AlignmentNot AvailableNot AvailableNot AvailableAvailableNot Available

Change Global Display Options

Through the Colors & Fonts dialog box, you can specify a color scheme for the chart or specify colors and label fonts for different types of objects in a chart. To open the Colors & Fonts dialog box, in the Format tab, click Style.

In the Colors & Fonts dialog box, the drawing area displays examples of the colors and label fonts specified by the current color scheme for the chart. You can choose a different color scheme from the Schemes menu. To modify the display options for a single type of chart element, position your pointer over the sample object.

  • To change the color of the element, click the sample object and select a new color in the dialog box.

  • To change the font of the element, right-click the sample object and select a new font, style, or size in the dialog box.

To apply the scheme to the chart, click Apply. To apply the scheme and close the dialog box, click OK.

To make the scheme the default scheme for all charts, select Options > Make this the 'Default' scheme.

To save changes to the default color scheme, select Options > Save defaults to disk. If the modified scheme is not the default scheme, choosing Save defaults to disk has no effect.

Content Preview for Stateflow Objects

When a chart is closed, you can preview the content of Stateflow charts in Simulink. You can see an outline of the contents of a chart. During simulation, you can see chart animation. When a chart is open, you can preview the content of subcharts and Simulink functions.

For example, the Temporal Logic chart uses content preview. The chart Without Temporal Logic does not.

To turn on content preview for Stateflow charts and subcharts, right-click the chart and select Format > Content Preview. For Simulink functions, right-click the function and select Content Preview. For details on content preview in Simulink, see Preview Content of Model Components (Simulink).

Note

In order to see the content preview, you may need to enlarge the Stateflow chart or object.

Intelligent Tab Completion for Stateflow Charts

Stateflow tab completion provides context-sensitive editing assistance. Tab completion helps you avoid typographical errors. It also helps you quickly select syntax-appropriate options for keywords, data, event, messages, and function names, without having to navigate the Model Explorer. In a Stateflow chart, to complete entries:

  1. Type the first few characters of the word that you want.

  2. Press Tab to see the list of possible matches.

  3. Use the arrow keys to select a word.

  4. Press Tab to make the selection.

Additionally, you can:

  • Close the list without selecting anything by pressing the Esc key.

  • Type additional characters onto your original term to narrow the list of possible matches.

If you press Tab and no words are listed, then the current word is the only possible match.

Differentiate Elements of Action Language Syntax

You can use color highlighting to differentiate the following syntax elements:

  • Keyword

  • Comment

  • Event

  • Message

  • Function

  • String

  • Number

Syntax highlighting is a user preference, not a model preference.

Default Syntax Highlighting

The following chart illustrates the default highlighting for language elements.

If the parser cannot resolve a syntax element, the chart displays the element in the default text color.

To modify color assignments, see Edit Syntax Highlighting. To disable syntax highlighting, see Enable and Disable Syntax Highlighting.

Edit Syntax Highlighting

  1. In the Stateflow Editor, in the Format tab, click Style > Syntax Highlighting.

    The Syntax Highlight Preferences dialog box appears.

  2. Click the color that you want to change, choose an alternative from the color palette, and click Apply.

  3. Click OK to close the Syntax Highlight Preferences dialog box.

Enable and Disable Syntax Highlighting

  1. In the Stateflow Editor, in the Format tab, click Style > Syntax Highlighting.

    The Syntax Highlight Preferences dialog box appears.

  2. Select or clear Enable syntax highlighting and click OK.

Select and Deselect Graphical Objects

Once an object is in the drawing area, to make any changes or additions to that object, select it.

  • To select an object, click anywhere inside of the object.

  • To select multiple adjacent objects, click and drag a selection box so that the box encompasses or touches the objects that you want to select, and then release the mouse button.

    All objects or portions of objects within the box become selected.

  • To select multiple separate objects, simultaneously press the Shift key and click an object or box a group of objects.

    This step adds objects to the list of already selected objects unless an object was already selected, in which case, the object is deselected. This type of multiple object selection is useful for selecting objects within a state without selecting the state itself.

  • To deselect all selected objects, click in the drawing area, but not on an object.

When an object is selected, it appears highlighted in the color set as the selection color (blue by default; see Specify Colors and Fonts in a Chart for more information).

Cut and Paste Graphical Objects

You can cut objects from the drawing area or cut and then paste them as many times as you like. You can cut and paste objects from one chart to another. The chart retains a selection list of the most recently cut objects. The objects are pasted in the drawing area location closest to the current pointer location.

  • To cut an object, right-click the object and select Cut from the context menu.

  • To paste the most recently cut selection of objects, right-click in the chart and select Paste from the context menu.

Copy Graphical Objects

To copy and paste an object in the drawing area, select the objects and right-click and drag them to the desired location in the drawing area. This operation also updates the chart clipboard.

Note

If you copy and paste a state in the chart, these rules apply:

  • If the original state uses the default ? label, then the new state retains that label.

  • If the original state does not use the default ? label, then a unique name is generated for the new state.

Alternatively, to copy from one chart to another, select Copy and then Paste from the right-click context menu.

Comment Out Objects

To Comment Out a Stateflow object, right-click the selected object and select Comment Out. For more information, see Commenting Stateflow Objects in a Chart.

Format Chart Objects

To enhance readability of objects in a chart, in the Stateflow Editor you can use commands in the Format tab. These commands include options for:

  • Alignment

  • Distribution

  • Resizing

You can align, distribute, or resize these chart objects:

  • States

  • Functions

  • Boxes

  • Junctions

Some of these options appear only after selecting elements within your chart.

Align, Distribute, and Resize Chart Objects

The basic steps to align, distribute, or resize chart objects are similar.

  1. If the chart includes parallel states or outgoing transitions from a single source, make sure that the chart uses explicit ordering.

    To set explicit ordering, in the Chart properties dialog box, select User specified state/transition execution order.

    Note

    If a chart uses implicit ordering to determine execution order of parallel states or evaluation order of outgoing transitions, the order can change after you align, distribute, or resize chart objects. Using explicit ordering prevents this change from occurring. For more information, see Execution Order for Parallel States and Transition Evaluation Order.

  2. Select the chart objects that you want to align, distribute, or resize.

    You can select objects in any order, one-by-one or by drawing a box around them.

  3. Decide which object to use as the anchor for aligning, distributing, or resizing other chart objects. This object is the reference object.

    To set an object as the reference, right-click the object. Brackets appear around the reference object. In the following example, the Door and Motion states are selected, and the Door state is the reference.

    Note

    If you select objects one-by-one, the last object that you select acts as the reference.

  4. Select an option from the Format tab to align, distribute, or resize your chosen objects.

    For more information about chart object distribution options, see Options for Distributing Chart Objects

Options for Distributing Chart Objects

OptionDescription
Distribute Horizontally

The center-to-center horizontal distance between any two objects is the same.

Note

The horizontal space for distribution is the distance between the left edge of the leftmost object and the right edge of the rightmost object. If the total width of the objects you select exceeds the horizontal space available, objects can overlap after distribution.

Distribute Vertically

The center-to-center vertical distance between any two objects is the same.

Note

The vertical space for distribution is the distance between the top edge of the highest object and the bottom edge of the lowest object. If the total height of the objects you select exceeds the vertical space available, objects can overlap after distribution.

Even Horizontal Gaps

The horizontal white space between any two objects is the same.

Note

The space restriction for Distribute Horizontally applies.

Even Vertical Gaps

The vertical white space between any two objects is the same.

Note

The space restriction for Distribute Vertically applies.

Example of Aligning Chart Objects

Suppose that you open the sf_pool model and see a chart with multiple MATLAB functions.

To align the three MATLAB functions on the right:

  1. Open the sf_pool model. Double-click the Pool block to open the chart.

    Tip

    Expand the Stateflow Editor to see the entire chart.

  2. Click the function isAnyBallGoingToStop.

  3. Shift-click the function isAnyBallNewlyPocketed.

  4. Shift-click the function getBallInteraction.

    This object is the reference (or anchor) for aligning the three functions. Brackets appear around the function.

  5. In the Format tab, click Align Right.

    This step aligns the right edges of the three functions based on the right edge of getBallInteraction.

Example of Distributing Chart Objects

Suppose that you open the sf_frame_sync_controller model and see a chart with three states.

To distribute the three states vertically:

  1. Open the sf_frame_sync_controller model.

    Tip

    Double-click the Frame Sync Controller block to open the chart.

  2. Select the three states in any order.

    Shift-click to select more than one state.

    Note

    When you select the three states in any order, your reference object might differ from the one shown. This difference does not affect distribution of vertical white space.

  3. In the Format tab, click Even Vertical Gaps.

    This step ensures that the vertical white space between any two states is the same.

Example of Resizing Chart Objects

Suppose that you open the sf_clutch_enabled_subsystems model and see a chart with graphical functions of different sizes.

To resize the graphical functions so that they all match the size of detectSlip:

  1. Open the sf_clutch_enabled_subsystems model.

  2. In the Friction Mode chart, select the three graphical functions by drawing a box around them.

  3. Set detectSlip as the reference object to use for resizing.

    Right-click the function to mark it with brackets.

  4. In the Format tab, click Match Size.

    This step ensures that the three functions are the same size.

  5. Adjust the function boxes to correct the format:

    1. In the Format tab, click Align Left.

    2. In the Format tab, click Even Vertical Gaps.

Automatic Chart Formatting

With Arrange Automatically, Stateflow arranges your charts to:

  • Expand states and transitions to fit their label strings.

  • Resize similar states to be the same size.

  • Align states if they were slightly misaligned.

  • Straightens transitions.

  • Repositions horizontal transition labels to the midpoint.

In the Format tab, click Auto Arrange.

In this example, the chart has:

  1. State actions that are outside of the boundary for state A.

  2. A transition condition that overlaps state B.

  3. A transition that is not horizontal.

After the layout has been automatically arranged:

  1. The state actions are contained within state A.

  2. The transition condition does not overlap into state B.

  3. The lower transition is horizontal.

Generate a Model Report

The Print Details report is an extension of the Print Details report in the Simulink model window. It provides a report of Stateflow and Simulink objects relative to the chart currently in view from which you select the report.

To generate a model report on chart objects:

  1. Open the chart or subchart for which you want a report.

  2. In the Simulation tab, select Print > Print Details.

    The Print Details dialog box appears.

  3. Enter the destination directory of the report file and select options to specify what objects appear in the report.

    For details on setting the fields in the File locations/naming options section, see Print Model Reports (Simulink). For details on the report you receive, see System Report Options and Report Format.

  4. Click Print.

The Print Details dialog box appears and tracks the report generation. See Print Model Reports (Simulink) for more details on this window.

The HTML report appears in your default browser.

Tip

If you have the Simulink Report Generator™ installed, you can generate a detailed report about a system. To do so, in the Modeling tab, select Compare > System Design Description Report. For more information, see System Design Description (Simulink Report Generator).

System Report Options

Reports for the current Stateflow chart vary with your choice of one of the System reporting options fields:

  • Current — Reports on the chart or subchart in the current editor window and its immediate parent Simulink system.

  • Current and above — This option is grayed out and unavailable for printing chart details.

  • Current and below — Reports on the chart or subchart in the current editor window and all contents at lower levels of the hierarchy, along with the immediate Simulink system.

  • Entire model — Reports on the entire model including all charts and all Simulink systems.

    If you select this option, you can modify the report as follows:

    • Look under mask dialog – Includes the contents of masked subsystems in the report.

    • Expand unique library links – Includes the contents of library blocks that are subsystems in the report.

      The report includes a library subsystem only once even if it occurs in more than one place in the model.

Report Format

The general top-down format of the Print Details report is as follows:

  • The report shows the title of the system in the Simulink model containing the chart or subchart in current view.

  • A representation of Simulink hierarchy for the containing system and its subsystems follows. Each subsystem in the hierarchy links to the report of its Stateflow charts.

  • The report section for the Stateflow charts of each system or subsystem begins with a small report on the system or subsystem, followed by a report of each contained chart.

  • Each chart report includes a reproduction of its chart with links for subcharted states that have reports of their own.

  • An appendix tabulates the covered Stateflow and Simulink objects in the report.