Main Content

Access Properties and Methods of Stateflow Objects

You manipulate Stateflow® API objects by changing their properties or calling their methods.

Properties correspond to values that you normally set for an object through the Stateflow Editor. For example, you can change the position of a state by changing the Position property of the corresponding State object:

st.Position = [10 20 100 80];

Methods provide services that are normally provided by the Stateflow Editor. For example, you can delete a transition in a chart by calling the delete method of the corresponding Transition object:


Naming Conventions for Properties and Methods

The names of all API properties and methods use camel case. If a name consists of two or more concatenated words, the words following the first word are capitalized.

  • Property names begin with a capital letter. For example, State objects have properties called Name and LabelString.

  • Method names begin with a lowercase letter. For example, Transition objects have methods called dialog and fitToView.

Access Properties and Methods

Dot Notation

To access the properties and methods of an object, use dot notation. Enter a handle for the object followed by a period (.) and the name of the property or method. For example, to see the value of the StateMachineType property for the Chart object ch, enter:


To open the Chart properties dialog box, call the dialog method of the Chart object:


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

ch.Debug.Breakpoints.OnEntry = true;

When a property or method returns a handle to another API object, you can also access the properties and methods for the second object by using nested dot notation. For example, the Machine property of a Chart returns a handle to the Stateflow machine that contains the corresponding chart. To access the Name property of this Machine object, enter the expression:

machineName = ch.Machine.Name;

Similarly, the defaultTransitions method returns a vector of handles to the default transitions in the chart. If the chart contains only one default transition, you can retrieve its label by entering:

label = ch.defaultTransitions.LabelString;

If the chart contains more than one default transition, you must first store the default transitions and then use an array index to retrieve each label:

transitions = ch.defaultTransitions;
label1 = transitions(1).LabelString;
label2 = transitions(2).LabelString;

Function-Call Notation

As an alternative to dot notation, you can call the methods of API objects by using standard function-call notation. For example, you can call the dialog method for a Chart object ch by using one of these commands:

ch.dialog                                      % dot notation
dialog(ch)                                     % function-call notation

Get and Set the Values of Properties

You can access the properties of an API object directly or by calling the get method. For example, you obtain the description for the Chart object ch with one of these commands:

description = ch.Description;                  % direct access
description = ch.get('Description');           % get method -- dot notation
description = get(ch,'Description');           % get method -- function-call notation

Similarly, you can change the value of a property directly or by calling the set method. For example, you change the description of the Chart object ch with one of these commands:

ch.Description = 'Half-wave rectifier.';       % direct access
ch.set('Description','Half-wave rectifier.');  % set method -- dot notation
set(ch,'Description','Half-wave rectifier.');  % set method -- function-call notation

Use the get and set methods to access or modify a property for every object in an array. For example, these commands return a cell array with the names of each chart in the array of Chart objects chartArray:

names = chartArray.get('Name');                % dot notation
names = get(chartArray,'Name');                % function-call notation

Display Properties and Methods

Display Property Information

To display information about API properties, you can use the help, get, and classhandle methods.

The help method displays the name and a short description of each property of an object.

The get method displays a list of the names and values of the properties of an object.


You can also use 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 Chart object ch, enter:


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


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



Some properties do not have descriptions. When a property is sufficiently descriptive, the corresponding description is an empty character vector. For more information on these properties, see Properties and Methods Sorted by Stateflow Object.

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 method. For example, this command displays the enumerated values allowed for the Decomposition property of a Chart object:

decompositionValues = ch.set('Decomposition')

Display API Methods

The methods method displays a list of the methods of an object.


You can also use a combination of the get and classhandle methods to list the names of the methods for an object:



The methods method lists some internal methods that are not documented. For a list of all documented methods, see Properties and Methods Sorted by Stateflow Object.

See Also

| | | |

Related Topics