Main Content

Modify Properties and Call Functions of Stateflow Objects

Stateflow® API objects have properties that correspond to values that you normally set through the Stateflow Editor. For example, to change the position of a state, you normally click and drag the state. With the Stateflow API, you change the position of a state by modifying the Position property of the corresponding Stateflow.State object:

st.Position = [10 20 100 80];

Additionally, object functions provide services that are normally provided by the Stateflow Editor. For example, to open the Properties dialog box for a transition, you typically right-click the transition and select Properties. With the Stateflow API, you open this dialog box by calling the dialog function of the corresponding Stateflow.Transition object:

dialog(tr);

Use Properties and Object Functions

Function-Call Notation

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 object ch:

dialog(ch)

Dot Notation

To access a property of an API object, use dot notation. For example, to see the value of the StateMachineType property for the Stateflow.Chart object ch, enter:

ch.StateMachineType

Similarly, to change the action language of the chart, modify its ActionLanguage property:

ch.ActionLanguage = 'MATLAB'

Nested Dot Notation

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 subproperty Debug.Breakpoints.OnEntry of the corresponding Stateflow.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 a Stateflow.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 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'});

Similarly, you can change the value of multiple properties by calling the set function. For example, to change the name and description of the Stateflow.Chart object ch, enter:

set(ch,{'Name','Description'},{'Rectifier','Half-wave rectifier.'})

You can use the get and set functions to access or modify properties for every object in an array. For example, this command returns a cell array with the names and descriptions of the Stateflow.Chart objects in the array chartArray:

chartInfo = get(chartArray,{'Name','Description'});

Display Property Information

The get function displays the names and values of the properties of an object. For example, to see the values of the properties of the Stateflow.Chart object ch, enter:

get(ch)

You can also call get to display the values of a subproperty of an object. For example, to see the values of the subproperties of the StateFont property of the Stateflow.Chart object ch, enter:

get(ch.StateFont)

Display Enumerated Values for Properties

Many API properties accept a limited number of possible values. To display a list of acceptable values for a property, call the set function. For example, this command displays the enumerated values allowed for the Decomposition property of a Stateflow.Chart object:

set(ch,'Decomposition')

Display Additional Information for Properties

You can display additional information about the properties of an object by using the function classhandle. For example, this command displays a list of property names and data types of a Stateflow.Chart object:

get(classhandle(ch).Properties,{'Name','DataType'})

To see the fields that you can use with this syntax, enter:

get(classhandle(ch).Properties)

See Also

Functions

Objects

Related Topics