The Stateflow® API consists of objects that represent the graphical and nongraphical
objects of a Stateflow chart. For example, API objects of type
Stateflow.Transition represent states
and transitions in a Stateflow chart.
Stateflow API objects are organized in the containment hierarchy described in
Hierarchy of Stateflow API Objects. To
create a Stateflow object as the child of a parent object, you begin by accessing the
parent object. Then use the parent object as the input argument to a function that
creates th child object. For example, to add a new
Stateflow.State object in a
Stateflow.Chart object, follow these
Access the parent object
described in Access Objects in Your Stateflow Chart.
using the parent object
ch as an argument.
st = Stateflow.State(ch);
Display the new state in the Stateflow Editor by calling the
view function. Use the
Stateflow.State object as the argument to the
Make changes to the state by modifying the properties
Stateflow.State object. For example, you can set the
name and position of the state by modifying the
Position properties. To set the
Position property, specify the new position as a
four-element vector in which the first two values are the (x,y) coordinates of the upper-left corner of the state and the
last two values are the width and height of the state.
st.Name = 'A'; st.Position = [30 30 90 60];
You can also connect the new state to other states or junctions in your
chart by creating a
object and setting its
Destination properties to
For an example of how to add states, transitions, and data objects to a chart, see Create Charts by Using the Stateflow API.
When you create a graphical object such as a state, function, box, junction,
or annotation, it appears in the upper-left corner of its parent object. You can
move the graphical object to a different location by modifying its
Position property, as explained in the previous
When you create a transition, it appears in the upper-left corner of the chart
or subchart where you can view the parent object. You can move the transition to
a different location by setting its source and destination or by modifying its
A graphical object must be located inside the boundary of its parent.
Repositioning a graphical object can change its parent or result in an undefined
parent error. You can check for this condition by examining the value of the
BadIntersection property of an object. This property is
true if the edges of the graphical object overlap with
another graphical object. Set the position and size of objects so that they are
separate from other objects.
You cannot move an object in a subcharted state, box, or graphical function to a different level of the chart hierarchy by changing its position. Instead, copy and paste the object from one parent object to another. Then delete the original object. For more information, see Copy and Paste by Grouping and Copy and Paste Array of Objects.
When you create nongraphical objects such as data, events, or messages, they
appear in the Model Explorer and in the Symbols Pane at the hierarchical level
of their parent object. You can also see the location of the parent object by
Path property of an object.
You cannot change the parent of a nongraphical object programmatically. Instead, use the Model Explorer. For more information, see Use the Model Explorer with Stateflow Objects.
You can delete most objects in a Stateflow chart by calling the function
delete. For example, to delete a
After you delete the state, the variable
st still exists in the
MATLAB® workspace, but it is no longer associated with the state.
You cannot use the
delete function to delete objects of