Skip to Main Content Skip to Search
Product Documentation

Editor Operations

Stateflow Editor Window

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:

Keyboard Shortcuts for Stateflow Charts

You can use the following keyboard shortcuts in the Stateflow Editor.

Task

Windows® platformUNIX® 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:

  • If you are editing the label of an object, the Esc key disables label editing but leaves the object selected.

  • If objects are selected, the Esc key deselects all objects in the current view.

  • If the current chart view is the contents of a subchart and no object is selected, the Esc key changes the view to the parent of the subchart.

  • If the current chart view is at the chart level and no object is selected, the Esc key displays the model window for that chart's block.

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 leftd or D or Ctrl+Left Arrowd or D or Ctrl+Left Arrow
Pan rightg or G or Ctrl+Right Arrowg or G or Ctrl+Right Arrow
Pan upe or E or Ctrl+Up Arrowe or E or Ctrl+Up Arrow
Pan downc or C or Ctrl+Down Arrowc or C or Ctrl+Down Arrow
Go back in pan/zoom historyb or Bb or B
Go forward in pan/zoom historyt or Tt 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

Displaying the Context Menu for Objects

Every object that you create in a chart has a shortcut menu associated with it. To display the shortcut (context) menu:

  1. Move your pointer over the object.

  2. Right-click the object.

    A menu of operations that apply to the object appears.

To display the context menu for the chart object:

  1. Move your pointer to an unoccupied location in the chart.

  2. Right-click the location.

    A menu of operations that apply to the chart appears.

Specifying Colors and Fonts in a Chart

You can specify the color and font for items in a chart, for a single item or all items in the chart.

Changing Fonts for a Single Item

You can change the font for a single item as follows:

  1. Right-click the item.

  2. In the context menu, select Font Size > size of font.

Using the Colors & Fonts Dialog Box

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.

Differentiating Syntax Elements in the Stateflow Action Language

You can use color highlighting to differentiate the following syntax elements in the Stateflow action language:

Default Syntax Highlighting

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.

Editing Syntax Highlighting

To edit syntax highlighting:

  1. In the Stateflow Editor, select Edit > Highlighting Preferences.

    The Syntax Highlight Preferences dialog box appears.

  2. Click the color 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.

Enabling and Disabling Syntax Highlighting

You can toggle syntax highlighting from the Tools and Edit menus in the Stateflow Editor.

Selecting and Deselecting Graphical Objects

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:

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

Cutting and Pasting 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.

Copying 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's clipboard.

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

Formatting Chart Objects

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:

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

Basic Steps for Aligning, Distributing, or Resizing Chart Objects

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

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

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

  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, similar to this:

      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 menu to align, distribute, or resize your chosen objects.

Options for Aligning Chart 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

Options for Distributing Chart Objects

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.

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

Make Horizontal Gaps Even

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

    Note   The space restriction for Distribute Items Horizontally applies.

Make Vertical Gaps Even

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

    Note   The space restriction for Distribute Items Vertically applies.

Options for Resizing Chart Objects

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

Example of Aligning Chart Objects

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:

  1. Type sf_pool at the MATLAB command prompt to open the model.

      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. Select Format > Align Items > Align Right Edges.

      Note   You can also right-click the reference object and select the option from the Format menu.

    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 demo model and see a chart with three states.

To distribute the three states vertically:

  1. Type sf_frame_sync_controller at the MATLAB command prompt to open the 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.

  3. Select Format > Distribute Items > Make Vertical Gaps Even.

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

      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.

Example of Resizing Chart Objects

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:

  1. Type sf_clutch at the MATLAB command prompt to open the 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. Select Format > Resize Items > Make Items Same Size.

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

  5. Adjust the function boxes to correct the format:

    1. To align the functions, select Format > Align Items > Align Left Edges.

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

Editing Object Labels

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:

  1. Select the states whose label font size you want to change.

  2. Right-click and select Font Size.

  3. Select the desired font size.

    The chart changes the font size of all labels on all selected states to the selected size.

Zooming a Chart

You can magnify or shrink a chart, using the following zoom controls:

Using the Zoom Factor Selector

The Zoom Factor Selector lets you to specify the zoom factor by:

Zooming with Shortcut Keys

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.

Moving in Zoomed Charts with Shortcut Keys

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.

Undoing and Redoing Editor Operations

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:

To redo an operation in the chart, do one of the following:

Exceptions for Undo

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

Printing Stateflow Charts

Printing Scaled Charts

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:

  1. Open the chart or subchart you want to print.

  2. In the editor, select File > Print.

    The Print Model dialog box appears:

  3. In the Print Model dialog box, select your printer and number of copies.

  4. Select the charts you want to print by choosing one of these options:

    OptionDescription
    Current systemPrints the current chart or subchart
    Current system and abovePrints the current chart or subchart and all systems above it in the model hierarchy
    Current system and belowPrints 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 systemsPrints all systems in the model hierarchy, with the option of looking into the contents of masked and library Simulink blocks

  5. Customize your print job as needed using these options:

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

  6. Click OK.

For more information about all print options, see Printing a Block Diagram in the Simulink documentation.

Using Tiled Printing for Stateflow Charts

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:

  1. Open the chart or subchart you want to print.

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

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

      Note   Stateflow software uses a row-major scheme to number tiled pages. For example, the first page of the first row is 1, the second page of the first row is 2, and so on.

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

Generating 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 editor, select File > Print Details.

    The Print Details dialog box appears as follows:

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

  4. Click Print.

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.

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

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

Printing the Current Chart

The Print Current View option prints an individual chart or subchart as follows:

  1. Open the chart or subchart that you want to print.

  2. In the editor, select File > Print Current View.

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

Customizing the Stateflow Editor

You can write MATLAB code to customize the Stateflow Editor by:

Adding Items to Stateflow Editor Menus

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 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};
end

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.

Disabling and Hiding Stateflow Editor Menu Items

You can disable or hide items that appear on Stateflow Editor menus by

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';
end

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:

Displaying Menu Tags

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;

  


Free Stateflow Interactive Kit

Learn how engineers use Stateflow to model state machines in their Simulink models.


Get free kit

Trials Available

Try the latest version of Stateflow.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS