| Contents | Index |
You use the Stateflow Editor to draw, zoom, modify, print, and save a chart shown in the window. It has the following appearance:

The Stateflow Editor window includes the following elements:
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.
Most editor commands are available from the menu bar.
Contains buttons for cut, copy, paste, and other commonly used editor commands. You can identify each tool of the toolbar by placing your pointer over it until an identifying tool tip appears.
The toolbar also contains buttons for navigating a chart's subchart hierarchy (see Navigating Subcharts).
Displays a set of tools for drawing states, transitions, and other state chart objects.
Displays an editable copy of a chart.
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 shortcut menu applies to the chart object. See Displaying the Context Menu for Objects for more information.
Displays tool tips and status information.
You can use the following keyboard shortcuts in the Stateflow Editor.
Task | Windows® platform | UNIX® platform |
|---|---|---|
Display the parent of the currently displayed chart or subchart. There is no limit on the time between the entry of each period. | .. (two periods) | .. (two periods) |
Zoom in by an incremental amount. | + or r or R | + or r or R |
Zoom out by an incremental amount. | - or v or V | - or v or V |
Fit chart to screen. | 0 or Space Bar | 0 or Space Bar |
Zoom to normal view. | 1 | 1 |
Move the current view down within the full chart. | 2 | 2 |
Move the current view down and right within the full chart. | 3 | 3 |
Move the current view left within the full chart. | 4 | 4 |
Fit the currently selected object to full view. If no object is selected, the chart is fit to full view. | 5 | 5 |
Move the current view right within the full chart. | 6 | 6 |
Move the current view up and left within the full chart. | 7 | 7 |
Move the current view up within the full chart. | 8 | 8 |
Move the current view up and right within the full chart. | 9 | 9 |
Delete the selected objects. | Delete | Delete |
Access the contents of the currently highlighted subchart or truth table. | Enter | Enter |
Perform any of the following actions:
| Esc | Esc |
Fit the currently selected object to screen. If no object is selected, the chart is fit to screen. | f or F | f or F |
| Pan left | d or D or Ctrl+Left Arrow | d or D or Ctrl+Left Arrow |
| Pan right | g or G or Ctrl+Right Arrow | g or G or Ctrl+Right Arrow |
| Pan up | e or E or Ctrl+Up Arrow | e or E or Ctrl+Up Arrow |
| Pan down | c or C or Ctrl+Down Arrow | c or C or Ctrl+Down Arrow |
| Go back in pan/zoom history | b or B | b or B |
| Go forward in pan/zoom history | t or T | t or T |
Select the first state, function, truth table, or box parented (contained) by the currently selected object in the same chart. Selection order of contained objects is top-down, left-right. See also u key. | j (jump) or J | j (jump) or J |
Select the next state, function, truth table, or box at the same containment level. Selection order of objects is top-down, left-right. | n (next) or N | n (next) or N |
Select the previous state, function, truth table, or box at the same containment level. Selection order of objects is top-down, left-right. | p (previous) or P | p (previous) or P |
Disable (or enable) smart transitions. To create self-loop transitions, disable smart mode. For details, see Creating Self-Loop Transitions. To maintain straight lines from transition sources, enable smart mode (the default). For details, see What Smart Transitions Do. | s (smart) or S | s (smart) or S |
Select the parent object of the currently highlighted object in the same chart. See also j key. | u (up) or U | u (up) or U |
Every object that you create in a chart has a shortcut menu associated with it. To display the shortcut (context) menu:
A menu of operations that apply to the object appears.
To display the context menu for the chart object:
A menu of operations that apply to the chart appears.
You can specify the color and font for items in a chart, for a single item or all items in the chart.
You can change the font for a single item as follows:
The Colors & Fonts dialog box helps you specify a color scheme for the chart as a whole, or colors and label fonts for different types of objects in a chart.
To display the Colors & Fonts dialog box, select Edit > Style in the Stateflow Editor.

The drawing area of the dialog box displays examples of the types of objects whose colors and font labels you can specify. The examples use the colors and label fonts specified by the current color scheme for the chart. To choose another color scheme, select the scheme from the dialog box's Schemes menu. The dialog box displays the selected color scheme. Click Apply to apply the selected scheme to the chart or OK to apply the scheme and dismiss the dialog box.
To make the selected scheme the default scheme for all charts, select Make this the "Default" scheme from the dialog box's Options menu.
To modify the current scheme, position your pointer over the example of the type of object whose color or label font you want to change. Then left-click to change the object's color or right-click to change the object's font. If you left-click, a color chooser dialog box appears.

Use the dialog box to select a new color for the selected object type.
If the selected object is a label and you right-click, a font selection dialog box appears.

Use the font selector to choose a new font for the selected label.
To save changes to the default color scheme, select Save defaults to disk from the Colors & Fonts dialog box's Options menu.
You can use color highlighting to differentiate the following syntax elements in the Stateflow action language:
Keyword
Comment
Event
Function
String
Number
The following chart illustrates the default highlighting for each language element:

If the parser cannot resolve a syntax element, the chart displays the element in the default text color.
To modify color assignments, see Editing Syntax Highlighting. To disable syntax highlighting, see Enabling and Disabling Syntax Highlighting.
To edit syntax highlighting:
In the Stateflow Editor, select Edit > Highlighting Preferences.
The Syntax Highlight Preferences dialog box appears.
Click the color you want to change, choose an alternative from the color palette, and click Apply.
Click OK to close the Syntax Highlight Preferences dialog box.
You can toggle syntax highlighting from the Tools and Edit menus in the Stateflow Editor.
From the Tools menu, select or clear Syntax Coloring.
From the Edit menu, follow these steps:
Select Highlighting Preferences to open the Syntax Highlight Preferences dialog box.
Select or clear Enable syntax highlighting and click OK.
Once an object is in the drawing area, you need to select it to make any changes or additions to that object.
Select objects in a chart as follows:
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 you want to select, and then release the mouse button.
All objects or portions of objects within the box are 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 when you select a state and all of its objects and then Shift-click inside the containing state to deselect it.
To deselect all selected objects, press the Esc key.
Pressing the Esc key again displays the parent of the current chart.
When an object is selected, it appears highlighted in the color set as the selection color (blue by default; see Specifying Colors and Fonts in a Chart for more information).
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.
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's clipboard.
Note If you copy and paste a state in the chart, these rules apply.
|
Alternatively, to copy from one chart to another, select Copy and then Paste from the right-click context menu.
To enhance readability of objects in a chart, you can use commands in the Format menu of the Stateflow Editor. These commands include options for:
Alignment
Distribution
Resizing
You can align, distribute, or resize these chart objects:
States
Functions
Boxes
Junctions
The basic steps to align, distribute, or resize chart objects are:
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, select User specified state/transition execution order in the Chart properties dialog box.
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 Evaluation Order for Outgoing Transitions. |
Select the chart objects you want to align, distribute, or resize.
You can select objects in any order, one-by-one or by drawing a box around them.
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, similar to this:

Select an option from the Format menu to align, distribute, or resize your chosen objects.
The following options are available in the Format > Align Items menu.
| This option... | Aligns selected objects... |
|---|---|
| Align Top Edges | Along the top edges |
| Align Centers Horizontally | So that the centers fall on the same horizontal line |
| Align Bottom Edges | Along the bottom edges |
| Align Left Edges | Along the left edges |
| Align Centers Vertically | So that the centers fall on the same vertical line |
| Align Right Edges | Along the right edges |
The following options are available in the Format > Distribute Items menu.
| This option... | Distributes selected objects so that... |
|---|---|
| Distribute Items Horizontally | The center-to-center horizontal distance between any two objects is the same. |
| Distribute Items Vertically | The center-to-center vertical distance between any two objects is the same. |
| Make Horizontal Gaps Even | The horizontal white space between any two objects is the same. |
| Make Vertical Gaps Even | The vertical white space between any two objects is the same. |
The following options are available in the Format > Resize Items menu.
| This option... | Makes selected objects have... |
|---|---|
| Make Items Same Height | The same height |
| Make Items Same Width | The same width |
| Make Items Same Size | The same height and width |
Suppose that you open the sf_pool demo model and see a chart with multiple MATLAB functions.

To align the three MATLAB functions on the right:
Type sf_pool at the MATLAB command prompt to open the model.
Click the function isAnyBallGoingToStop.
Shift-click the function isAnyBallNewlyPocketed.
Shift-click the function getBallInteraction.
This object is the reference (or anchor) for aligning the three functions. Brackets appear around the function.

Select Format > Align Items > Align Right Edges.
This step aligns the right edges of the three functions based on the right edge of getBallInteraction.

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

To distribute the three states vertically:
Type sf_frame_sync_controller at the MATLAB command prompt to open the model.
Select the three states in any order.
Shift-click to select more than one state.
Select Format > Distribute Items > Make Vertical Gaps Even.
This step ensures that the vertical white space between any two states is the same.

Suppose that you open the sf_clutch demo 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:
Type sf_clutch at the MATLAB command prompt to open the model.
In the Friction Mode chart, select the three graphical functions by drawing a box around them.
Set detectSlip as the reference object to use for resizing.
Right-click the function to mark it with brackets.

Select Format > Resize Items > Make Items Same Size.
This step ensures that the three functions are the same size.

Adjust the function boxes to correct the format:
To align the functions, select Format > Align Items > Align Left Edges.

To distribute the functions, select Format > Distribute Items > Make Vertical Gaps Even.

Some Stateflow objects (for example, states and transitions) have labels. To change these labels, place your pointer anywhere in the label and click. Your pointer changes to an I-beam. You can then edit the text.
You can use the shortcut (context) menu to change a label's font size:
The chart changes the font size of all labels on all selected states to the selected size.
You can magnify or shrink a chart, using the following zoom controls:
Zoom Factor Selector. Selects a zoom factor (see Using the Zoom Factor Selector).
Zoom In button. Zooms in by the current zoom factor.
You can also press the R key to increase the zoom factor.
Zoom Out button. Zooms out by the current zoom factor.
You can also press the V key to decrease the zoom factor.
The Zoom Factor Selector lets you to specify the zoom factor by:
Choosing a value from a menu
Click the selector to display the menu.
Double-clicking the Zoom Factor Selector selects the zoom factor that will fit the view to all selected objects or all objects if none are selected.
You can achieve the same effect by choosing Fit to View from the right-click context menu or by pressing the F key to apply the maximum zoom that includes all selected objects. Press the space bar to fit all objects to the view.
Clicking the Zoom Factor Selector and dragging up or down.
Dragging the mouse upward increases the zoom factor. Dragging the mouse downward decreases the zoom factor. Alternatively, right-clicking and dragging on the percentage value resizes while you are dragging.
This table is a summary of the shortcut keys you can use to perform some of the zooming operations described above:
Key | Zoom Operation |
|---|---|
F | Highlight (select) an object and press the F key to fit it to view. |
space bar | Set to full view of chart. |
R or + | Increase zoom factor. |
V or - | Decrease zoom factor. |
You can also use number keys to move in zoomed charts according to their layout in the number keypad:

You can enter numbers for moving from the number keys above the alphabetic keys at any time or from the number keypad if NumLock is engaged for the keyboard. The 5 key fits the currently selected object to full view. If no object is selected, the entire chart is fit to view.
You can undo and redo operations you perform in the Stateflow Editor. When you undo an operation in the Stateflow Editor, you reverse the last edit operation you performed. After you undo operations in the Stateflow Editor, you can also redo them one at a time.
To undo an operation in the chart, do one of the following:
Click the Undo icon
in the toolbar:
.
When you place your pointer over the Undo button, the tool tip that appears indicates the nature of the operation to undo.
From the Edit menu, select Undo.
To redo an operation in the chart, do one of the following:
Click the Redo icon
in the toolbar:
.
When you place your pointer over the Redo button, the tool tip that appears indicates the nature of the operation to redo.
From the Edit menu, select Redo.
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 Using Subcharts to Encapsulate Modal Logic.
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 Drawing a Supertransition Into a Subchart and Drawing a Supertransition Out of a Subchart.
You cannot undo any changes made to the chart through the Stateflow API.
For a description of the Stateflow API (Application Programming Interface), see Using the API in the Stateflow API Guide.
By default, Stateflow software scales each chart that you print to fit on a single page. If you prefer to print charts without scaling to preserve clarity and detail, you can use tiled printing, as described in Using Tiled Printing for Stateflow Charts.
To print scaled charts, follow these steps:
In the editor, select File > Print.
The Print Model dialog box appears:

In the Print Model dialog box, select your printer and number of copies.
Select the charts you want to print by choosing one of these options:
| Option | Description |
|---|---|
| Current system | Prints the current chart or subchart |
| Current system and above | Prints the current chart or subchart and all systems above it in the model hierarchy |
| Current system and below | Prints the current chart or subchart and all systems below it in the model hierarchy, with the option of looking into the contents of masked and library Simulink blocks |
| All systems | Prints all systems in the model hierarchy, with the option of looking into the contents of masked and library Simulink blocks |
Customize your print job as needed using these options:
| Option | Description |
|---|---|
| Enable tiled printing for all systems | Enables tiled printing for all charts and overrides any individual tiled-print settings. See Using Tiled Printing for Stateflow Charts. |
| Include Print Log | Includes a list of all printed charts. |
| Look under mask dialog | Prints the contents of Simulink masked subsystems when encountered at or below the level of the current chart or subchart (when printing Current system and below) or the top-level system (when printing All systems). |
| Expand unique library links | Prints the contents of library blocks that appear in Simulink subsystems that are printed with Current system and below or All systems. |
| Print Sample Time Legend | Prints the Sample Time Legend on a separate page from your model. The legend contains sample time information for your entire model, including any subsystems. |
| Frame | Prints a title block frame with each chart. To learn how to create print frames, see PrintFrame Editor Overview in the Simulink User's Guide. |
Click OK.
For more information about all print options, see Printing a Block Diagram in the Simulink documentation.
Stateflow charts support Simulink tiled printing options (see Tiled Printing in the Simulink documentation). Tiled printing enables you to print Stateflow charts without scaling to fit a page and, therefore, without sacrificing clarity and detail. With tiled printing, you can distribute a chart over a specified number of pages and, therefore, control the total size of the printed image. You can choose different tiled-print settings for each of your charts to customize the appearance of all printed images.
If you want to scale charts to fit on a single printed page, see Printing Scaled Charts.
To print charts on tiled pages, follow these steps:
Open the chart or subchart you want to print.
In the editor, select File > Enable Tiled Printing.
To enable tiled printing for all systems in your model, select the Enable tiled printing for all systems check box on the Print Model dialog box
To visualize the chart's size and layout with respect to the page, select View > Show Page Boundaries.
If your chart is too large to fit on one page, the editor displays the page boundaries as tiles in a checkerboard pattern. When a state extends beyond the page boundary, you can select and drag the state to a different tile so that it prints in its entirety on a separate page.
Select File > Print.
By default, this command prints all of a system's tiled pages. Alternatively, you can specify a range of tiled page numbers to print. See Printing Tiled Pages in the Simulink documentation.
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:
In the editor, select File > Print Details.
The Print Details dialog box appears as follows:

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 of this dialog box, see Generating a Model Report in the Simulink software documentation. For details on the report you receive from the option you choose in the System reporting options section, see System Report Options and Report Format.
The Print Details dialog box appears and tracks the activity of the report generator during report generation. See Generating a Model Report in the Simulink software documentation for more details on this window.
If no serious errors occur, the HTML report appears in your default browser.
Note You can also use MATLAB® Report Generator™ software to generate a report that documents an entire model, including both Simulink and Stateflow objects. See the MATLAB Report Generator User's Guide. |
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.
The Print Current View option prints an individual chart or subchart as follows:
In the submenu, choose one of these options:
To File — Converts the current view to a graphics file.
Select the format for the graphics file from a submenu of graphical file types.
To Clipboard — Copies the current view to the system clipboard.
Select the format for the clipboard copy from a submenu of graphical formats.
To Figure — Converts the current view to a MATLAB figure window.
To Printer — Prints the current view on the current printer.
Tip You can also print the current view from the MATLAB command line using the sfprint function. |
You can write MATLAB code to customize the Stateflow Editor by:
Adding items and submenus to the end of Stateflow Editor menus (see Adding Items to Stateflow Editor Menus)
Disabling and hiding items on menus in the Stateflow Editor (see Disabling and Hiding Stateflow Editor Menu Items)
You use the Simulink customization manager to add items, including submenus, to the end of menus in the Stateflow Editor. For example, you can add menu items that invoke your own MATLAB functions.
To add an item to the end of a Stateflow Editor menu, you must create the following functions in an sl_customization.m file on the MATLAB path:
For each item, create a schema function, which defines a custom item on a menu owned by the Stateflow Editor.
Create a custom menu function, which registers schema functions that define custom items that you want to add to a menu.
Define the sl_customization function to register the custom menu function with the Simulink customization manager.
Create callback functions for the items that you add to the Stateflow Editor menus.
For detailed descriptions of these procedures, see Adding Items to Model Editor Menus in the Simulink User's Guide.
Code Example: Adding a Custom Submenu to the Stateflow Editor. The following sl_customization.m file adds a submenu called Set Font Style to the Stateflow Editor's Edit menu. The submenu contains three menu options for font style: Arial, Courier New, and Times New Roman. The sl_customization function accepts one argument, a customization manager object. For example, you can set cm = sl_customization_manager at the MATLAB command line.
function sl_customization(cm)
%% Register custom menu function.
cm.addCustomMenuFcn('Stateflow:EditMenu', @getMyMenuItems);
end
%% Define the custom submenu function.
function schemaFcns = getMyMenuItems(callbackInfo)
schemaFcns = {@getItem4};
end
%% Define the schema function for first submenu item
function schema = getItem1(callbackInfo)
schema = sl_action_schema;
schema.label = 'Arial';
schema.userdata = 'font style Arial';
schema.callback = @myCallback1;
end
%% Define the schema function for second submenu item.
function schema = getItem2(callbackInfo)
schema = sl_action_schema;
schema.label = 'Courier New';
schema.userdata = 'font style Courier New';
schema.callback = @myCallback1;
%% Define the schema function for third submenu item.
function schema = getItem3(callbackInfo)
schema = sl_action_schema;
schema.label = "Times New Roman';
schema.userdata = 'font style Times New Roman';
schema.callback = @myCallback1;
end
function myCallback1(callbackInfo)
disp(['Callback for 'callbackInfo.userdata' was called']);
end
function schema = getItem4(callbackInfo)
% Make a submenu label 'Set Font Style'
% with the font styles defined in menu items above.
schema = sl_container_schema;
schema.label = 'Set Font Style';
schema.childrenFcns = {@getItem1, @getItem2, @getItem3};
endNote The addCustomMenuFcn function requires that you pass a string argument that identifies the menu or menu item you wish to customize. To determine the appropriate tag, see Displaying Menu Tags. |
Custom Menu Example: Set Font Style. When you run sl_customization(cm) described in Code Example: Adding a Custom Submenu to the Stateflow Editor, the following new submenu appears in the Stateflow Editor.

You can disable or hide items that appear on Stateflow Editor menus by
Creating a filter function that disables or hides the menu item (see Creating a Filter Function in the Simulink User's Guide)
Registering the filter function with the Simulink customization manager (see Registering a Filter Function in the Simulink User's Guide)
For detailed descriptions of these procedures, see Disabling and Hiding Model Editor Menu Items in the Simulink User's Guide.
Code Example: Disabling the Print Command in the Stateflow Editor. The following sl_customization.m file disables the Print command in the File menu of the Stateflow Editor. The example assumes you set cm = sl_customization_manager.
function sl_customization(cm)
%%Register custom filter function.
cm.addCustomFilterFcn('Stateflow:PrintMenuItem', @myFilter);
end
function state = myFilter(callbackInfo)
state = 'Disabled';
endNote The addCustomFilterFcn function requires that you pass a string argument that identifies the menu or menu item you wish to disable or hide. To determine the appropriate tag, see Displaying Menu Tags. The myFilter function sets the state of the menu item. Valid states are:
|
Custom Menu Example: Disable Print Menu Item. After you run sl_customization(cm) described in Code Example: Disabling the Print Command in the Stateflow Editor, the Stateflow Editor's File menu looks like this:

To determine the tags that identify the menus or menu items you wish to customize on the Stateflow Editor, set the Simulink customization manager's showWidgetIdAsToolTip property to true by entering the following commands at the MATLAB command line:
cm = sl_customization_manager; cm.showWidgetIdAsToolTip = true;
After enabling this property, the tag of each menu or menu item appears next to its label in the Stateflow Editor:

To turn off tag display, enter the following command at the MATLAB command line:
cm.showWidgetIdAsToolTip = false;
Note Some Stateflow Editor menu items might not work while menu tags are visible. You should turn off menu tag display before attempting to use the menus. |
![]() | Working with Transitions in Charts | Modeling Logic Patterns and Iterative Loops Using Flow Graphs | ![]() |

Learn how engineers use Stateflow to model state machines in their Simulink models.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |