Main Content

Stateflow Programmatic Interface

Create and modify chart elements at the MATLAB® command prompt

Programmatically create and edit Stateflow® charts. Add new objects to your chart, access and edit properties, set positions, copy and paste objects, and change the magnification level of the Stateflow Editor.


expand all

sfnewCreate Simulink model that contains an empty Stateflow block
sfrootRoot of Stateflow hierarchy
sfclipboardClipboard object
sfgcoSelected objects in chart
Stateflow.findMatchingPortIdentify matching entry or exit port


expand all

Chart, Block, and Machine Objects

Stateflow.ChartGraphical representation of a finite state machine
Stateflow.StateTransitionTableChartTabular representation of state machine for modal logic
Stateflow.TruthTableChartTabular representation of state machine for decision logic
Stateflow.EMChartStateflow interface to MATLAB Function block
Stateflow.MachineContainer for Stateflow blocks in a Simulink model

Graphical Objects

Stateflow.AnnotationAnnotation in chart, state, box, or function
Stateflow.AtomicBoxAtomic box in chart, state, box, or function
Stateflow.AtomicSubchartAtomic subchart in chart, state, or box
Stateflow.BoxBox in chart, state, box, or function
Stateflow.EMFunctionMATLAB function in chart, state, box, or function
Stateflow.FunctionGraphical function in chart, state, box, or function
Stateflow.JunctionConnective or history junction in chart, state, box, or function
Stateflow.PortEntry or exit port in state or atomic subchart
Stateflow.SimulinkBasedStateSimulink based state in chart, state, or box
Stateflow.SLFunctionSimulink function in chart, state, box, or function
Stateflow.StateState in chart, state, or box
Stateflow.TransitionTransition in chart, state, box, or function
Stateflow.TruthTableTruth table function in chart, state, box, or function

Nongraphical Objects

Stateflow.DataData in chart, state, box, or function
Stateflow.EventEvent in chart, state, or box
Stateflow.MessageMessage in chart, state, or box

Clipboard and Editor Objects

Stateflow.ClipboardClipboard to copy and paste Stateflow objects
Stateflow.EditorGraphical aspects of a chart or state transition table

Object Functions

expand all

Navigate Hierarchy

findIdentify specified objects in hierarchy
getChildrenIdentify children of object
getParentIdentify parent of object
defaultTransitionsIdentify default transitions in specified object
innerTransitionsIdentify inner transitions with specified source
outerTransitionsIdentify outer transitions with specified source
sinkedTransitionsIdentify transitions with specified destination
sourcedTransitionsIdentify transitions with specified source

Access and Modify Properties

dialogOpen properties dialog box
setImageInsert image into annotation
isCommentedDetermine if graphical object is commented out

Control Display

viewDisplay object in editing environment
highlightHighlight graphical object
fitToViewZoom in on graphical object
zoomInZoom in on Stateflow chart
zoomOutZoom out on Stateflow chart

Copy and Paste Objects

copyCopy array of objects to clipboard
pasteToPaste objects in clipboard to specified container object


Overview of the Stateflow API

Create and edit Stateflow charts by using MATLAB commands.

Create and Delete Stateflow Objects

Design your Stateflow chart by adding and deleting objects.

Access Objects in Your Stateflow Chart

Locate objects contained in your Stateflow chart.

Modify Properties and Call Functions of Stateflow Objects

Manipulate Stateflow objects by modifying properties and calling functions.

Specify Labels in States and Transitions Programmatically

Add labels with one or more lines of text to states and transitions.

Set Simulation Parameters Programmatically

Use the command-line API to set parameters in the Model Configuration Parameters dialog box.

Featured Examples