Modify Properties and Call Functions of Stateflow Objects - MATLAB & Simulink (original) (raw)
Main Content
Stateflow® API objects have properties that correspond to the values you set in the Stateflow Editor. For example, to use the editor to change the position of a state, you click and drag the state. With the Stateflow API, you change the position of a state by modifying thePosition
property of the corresponding Stateflow.State object:
st.Position = [10 20 100 80];
Additionally, object functions provide services that correspond to actions in the Stateflow Editor. For example, to use the editor to open the Properties dialog box for a transition, you right-click the transition and select . With the Stateflow API, you open this dialog box by calling the dialog function of the corresponding Stateflow.Transition object:
Call Object Functions
To call a function of an API object, use standard function-call notation. For example, to open the Chart properties dialog box, call the dialog function of the corresponding Stateflow.Chart objectch
:
Access Properties by Using Dot Notation
To access a property of an API object, use dot notation. For example, to see the value of the StateMachineType
property for theStateflow.Chart
object ch
, enter:
Similarly, to change the action language of the chart, modify itsActionLanguage
property:
ch.ActionLanguage = "MATLAB";
To access the subproperties of an API property, you can nest multiple property names in a single expression that uses dot notation. For example, you can set an entry breakpoint on a chart by changing the subpropertyDebug.Breakpoints.OnEntry
of the correspondingStateflow.Chart
object:
ch.Debug.Breakpoints.OnEntry = true;
When a property or function returns another API object, you can also access the properties and functions for the second object by using nested dot notation. For example, the Machine
property of aStateflow.Chart
returns the Stateflow.Machine object that contains the corresponding chart. To access the Name
property of this Stateflow.Machine
object, enter the expression:
machineName = ch.Machine.Name;
Similarly, the defaultTransitions function returns an array of Stateflow.Transition
objects that correspond to the default transitions in the chart. If the chart contains only one default transition, you can retrieve its label by entering:
label = defaultTransitions(ch).LabelString;
If the chart contains more than one default transition, you must first store the array and then use an array index to retrieve each label:
transitions = defaultTransitions(ch); label1 = transitions(1).LabelString; label2 = transitions(2).LabelString;
Get and Set the Values of Multiple Properties
You can access multiple properties of an API object in a single command by calling the get
function. For example, to obtain the name and description for the Stateflow.Chart
object ch
, enter:
chartInfo = get(ch,{"Name","Description"});
You can also use the get
to access properties of multiple API objects. For example, this command returns a cell array that contains the names and descriptions of the Stateflow.Chart
objects in the arraychartArray
:
chartInfo = get(chartArray,{"Name","Description"});
Similarly, you can change the value of multiple properties by calling theset
function. For example, to change the name and description of the Stateflow.Chart
object ch
, enter:
set(ch,{"Name","Description"},{"Rectifier","Half-wave rectifier."})
To set the names and descriptions of the Stateflow.Chart
objects in the array chartArray
, enter:
set(chartArray,{"Name","Description"},chartInfo)
In this command, chartInfo
must be an_N
_-by-2 cell array, where N
equals the number of charts in chartArray
. The first column inchartInfo
contains the new chart names, and the second column contains the new descriptions.