Main Content

Stateflow Editor Operations

Stateflow Editor

The Stateflow® Editor allows you to draw, zoom, modify, print, and save a Stateflow chart in your Simulink® model. When you open a new Stateflow chart, the Stateflow Editor displays the chart.

To open a new Stateflow chart in the Stateflow Editor, at the MATLAB® command prompt, enter:

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

    The Simulink Editor opens, and an empty chart is included on the canvas.

  2. To open the Stateflow Editor, double-click the chart object.

Default view of the Stateflow Editor.

The main components of the Stateflow Editor are the chart canvas, the object palette, the Symbols pane, and the Property Inspector.

  • The chart canvas is a drawing area where you create a chart by combining states, transitions, and other graphical elements.

  • On the left side of the canvas, the object palette displays a set of tools for adding graphical elements to your chart. For more information, see Graphical Objects.

    To add an object:

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

  • On the right side of the canvas, in the Symbols pane, you add new data to the chart and resolve any undefined or unused symbols. Also on the right side of the canvas, above the Symbols pane, is the Property Inspector. Use the Property Inspector to change the properties for symbols listed in the Symbols pane. For more information, see Manage Symbols in the Stateflow Editor.

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.

Exceptions for Undo

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

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.

Colors and fonts dialog box.

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.

    State and frame color 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.

    Select font 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.

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

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

Two Stateflow charts. One chart has content preview enabled. The other has content preview disabled.

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:

  • Keywords

  • Comments

  • Events

  • Messages

  • Functions

  • Strings

  • Numbers

  • Local data

  • Constant data

  • Input data

  • Output data

  • Parameter data

  • Data Store Memory data

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

Default Syntax Highlighting

The following chart illustrates the default highlighting for language elements.

Stateflow chart showing default highlighting.

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

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.

Zoom and Navigate with the Miniature Map

To zoom in or out of a Stateflow chart, use the scroll wheel on your mouse. When you zoom Press and hold Space to see a dialog with the keyboard shortcuts.

Space bar pop-up

You can also press Space to view a miniature map of your chart in the bottom-left corner. As you zoom or navigate within your Stateflow chart, the blue square will move on the miniature map, indicating your location relative to the entire chart.

Mini map

You can also click and drag the blue square on the miniature map to navigate within your Stateflow chart. As you zoom out, the text in your Stateflow chart adjusts its size to maintain readability.

Zoomed out stateflow 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.

  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. If you select objects one-by-one, the last object that you select acts as the reference.

    Chart that contains three states: Door, Win, and Motion. Door is the reference state.

  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.

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.

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.

The space restriction for Distribute Horizontally applies.

Even Vertical Gaps

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

The space restriction for Distribute Vertically applies.

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.

Chart before automatic formatting.

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.

Chart after automatic formatting.

Related Topics