| Stateflow® | ![]() |
You use the Stateflow® Editor to draw, zoom, modify, print, and save a chart displayed 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.
See Viewing Stateflow® Objects in the Model Explorer for information on using the zoom control.
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 Stateflow Editor, the shortcut menu applies to the chart object. See Displaying the Context Menu for Objects for more information.
Displays tool tips and status information.
Every object that you create in a chart has a shortcut menu associated with it. To display the shortcut (context) menu, do the following:
A menu of operations that apply to the object appears.
To display the context menu for the chart object, do the following:
A menu of operations that apply to the chart appears.
You can specify the color and font for items in the Stateflow Editor, as described in the following topics:
Changing Fonts for an Individual Text Item — Tells you how to set color and font for an individual item in the Stateflow Editor.
Using the Colors & Fonts Dialog — Shows you how to set default colors and fonts for all Stateflow Editor items in the Colors and Fonts dialog
You can change the font for an individual text item as follows:
You can also specify the label font size of a particular object:
The Colors & Fonts dialog allows you to specify a color scheme for a chart as a whole, or colors and label fonts for different types of objects in a chart.
To display the Colors & Fonts dialog, select Edit > Style in the Stateflow Editor.

The drawing area of the dialog 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's Schemes menu. The dialog 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.
To make the selected scheme the default scheme for all charts, select Make this the "Default" scheme from the dialog'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 appears.

Use the dialog 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 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's Options menu.
Note Choosing Save defaults to disk has no effect if the modified scheme is not the default scheme. |
This release gives you the option of using color highlighting to differentiate the following syntax elements in the Stateflow action language:
Keyword
Comment
Event
Graphical function
String
Number
Note Syntax highlighting is a user preference, not a model preference. |
Syntax highlighting is enabled by default, assigning the following colors to syntax elements:

This Stateflow chart illustrates the default highlighting for each language element:

If the parser cannot resolve a syntax element, the Stateflow Editor 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, follow these steps:
In the Stateflow Editor, select Edit > Highlighting Preferences.
The Syntax Highlight Preferences dialog 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.
You can toggle syntax highlighting from the Tools and Edit menus in the Stateflow Editor. From the Tools menu, select Syntax Highlighting. From the Edit menu, follow these steps:
Select Highlighting Preferences to open the Syntax Highlight Preferences dialog.
Check or uncheck 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 the Stateflow Editor as follows:
To select an object, click anywhere inside of the object.
To select multiple adjacent objects, click and drag a selection rubberband so that the rubberband box encompasses or touches the objects you want to select, and then release the mouse button.
All objects or portions of objects within the rubberband are selected.
To select multiple separate objects, simultaneously press the Shift key and click an object or rubberband a group of objects.
This 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 rubberband select a state and all of its objects and then Shift-click inside the containing state to deselect it.
To select all objects in the Stateflow chart, from the Edit menu select Select All.
You can also select all objects by selecting Select All from the right-click shortcut menu.
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 is highlighted in the color set as the selection color (blue by default; see Specifying Colors and Fonts 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 Stateflow chart to another. The Stateflow Editor 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, select the object and choose Cut from one of the following:
The Edit menu on the Stateflow Editor
The right-click shortcut menu
To paste the most recently cut selection of objects, choose Paste from either of the following:
The Edit menu on the Stateflow Editor
The right-click shortcut 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 Stateflow clipboard.
Note If you copy and paste a state, a unique name is automatically generated for the new state. |
Alternatively, to copy from one Stateflow chart to another, choose the Copy and then Paste menu items from either of the following:
The Edit menu in the Stateflow Editor window
The right-click shortcut menu
You can group together states that contain other states (superstates).
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:
Place your pointer over the Font Size menu item.
A menu of font sizes appears.
Select the desired font size from the menu.
The Stateflow Editor changes the font size of all labels on all selected states to the selected size.
To view or modify Stateflow Editor objects in the Model Explorer, follow these steps:
Select Explore from the context menu.
The Model Explorer opens (if not already open) and highlights the state in the left hierarchy pane to show any data or events defined by the state.
To view data and events defined by the parent state of a transition or junction, select Explore from the transition or junction's context menu.
The Model Explorer is the only place where you can view and modify data and events. See Defining Data and Defining Events for more details on using the Model Explorer to view, add, delete, and modify data and events for Stateflow objects. See also Using the Model Explorer with Stateflow® Objects for more details on using the Model Explorer to view Stateflow objects.
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 allows 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.
Use the Stateflow API method fitToView to zoom in on a graphical object in the Stateflow Editor. (See Using the API in the Stateflow API documentation for information about obtaining object handles.)
You can zoom these objects in the Stateflow Editor:
Charts
Subcharts
States
Transitions
Graphical functions
Truth tables
Embedded MATLAB™ functions
Connective junctions
History junctions
Boxes
Notes
Follow these steps to zoom in on different states in the sf_car demo:
At the MATLAB® command prompt, type:
sf_car;
The chart shift_logic appears in the Stateflow Editor.
To define an object handle for the chart shift_logic, type:
myChart = find(sfroot,'-isa','Stateflow.Chart','name', ... 'shift_logic');
To define an object handle for the state upshifting, type:
myState = find(sfroot,'-isa','Stateflow.State','name', ... 'upshifting');
To zoom in on the state upshifting, type:
myState.fitToView;
The Stateflow Editor zooms in on the state and highlights it.

To define an object handle for the state downshifting, type:
myState = find(sfroot,'-isa','Stateflow.State','name', ... 'downshifting');
To zoom in on the state downshifting, type:
myState.fitToView;
The Stateflow Editor zooms in on the state and highlights it.

To zoom back to the chart level in the Stateflow Editor, type:
myChart.fitToView;
The chart shift_logic reappears, as shown below.

You can also zoom in on a state using the sfgco function. Follow these steps:
Click any state in the chart.
At the MATLAB command prompt, type:
myState = sfgco;
This command assigns the selected state to the object handle myState.
To zoom in on the selected state, type:
myState.fitToView;
The Stateflow Editor zooms in on the state and highlights it.
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 Stateflow Editor, do one of the following:
Select the Undo icon
in the toolbar of the Stateflow Editor
.
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 Stateflow Editor, do one of the following:
Select the Redo icon
in the toolbar of the Stateflow Editor
.
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 Stateflow 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 Extend Charts.
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 Stateflow Editor through the Stateflow API.
For a description of the Stateflow API (Application Programming Interface), see Using the API in the Stateflow API Guide.
You can use the chart notes dialog box to edit note properties.

The Note dialog contains the following properties for a chart note:
Field | Description |
|---|---|
Label | The label for the note. This includes the name of the note and its associated actions. |
Description | Textual description/comment. |
Use display text as click callback | Checking this option causes a Simulink® model to treat the text in the Text field as the note's click function. The specified text must be a valid MATLAB expression comprising symbols that are defined in the MATLAB workspace when the user clicks this annotation. Note that selecting this option disables the ClickFcn edit field. |
ClickFcn | Specifies MATLAB code to be executed when a user single-clicks this annotation. The Simulink model stores the code entered in this field. |
Document Link | Enter a URL address or a general MATLAB command. Examples are www.mathworks.com, mailto:email_address, and edit /spec/data/speed.txt. |
See Annotation Callback Functions in the Simulink User's Guide for a description of the ClickFcn edit field.
This table gives a comprehensive list of keyboard shortcuts for 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 Stateflow Editor view down within the full chart. | 2 | 2 |
Move the current Stateflow Editor view down and right within the full chart. | 3 | 3 |
Move the current Stateflow Editor 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 Stateflow Editor view right within the full chart. | 6 | 6 |
Move the current Stateflow Editor view up and left within the full chart. | 7 | 7 |
Move the current Stateflow Editor view up within the full chart. | 8 | 8 |
Move the current Stateflow Editor 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 |
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 |
You can write M-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 M-code 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. Your sl_customization function should accept one argument, a handle to an object called the Simulink.CustomizationManager. 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 may not work while menu tags are displayed. Thus, you should turn off menu tag display before attempting to use the menus. |
![]() | Creating Flow Graphs with Connective Junctions | Building Mealy and Moore Charts | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |