Access Properties and Methods of Stateflow Objects

Naming Conventions for Properties and Methods

By convention, all properties begin with a capital letter, for example, the property Name. However, if a property consists of concatenated words, the words following the first word are capitalized, for example, the property LabelString. The same naming convention applies to methods, with the exception that a method name must begin with a letter in lowercase; for example, the method find.

Using Dot Notation with Properties and Methods

You can access the properties and methods of an object by adding a period (.) and the name of the property or method to the end of an object's handle variable. For example, this command returns the Type property for a State object represented by the handle s:

stype = s.Type;

This command calls the dialog method of the State object s to open a properties dialog box for that state:

s.dialog;

Nesting Dot Notation

You can nest smaller dot expressions in larger dot expressions of properties. For example, the Chart property of a State object returns the Chart object of the containing chart. Therefore, the expression s.Chart.Name returns the name of the chart containing the State whose object is s.

Methods can also be nested in dot expressions. For example, if the State object sA1 represents state A1 in a chart, this command returns the label for state A1's inner transition to a substate A11.

label = sA1.innerTransitions.LabelString;

The preceding command uses the LabelString property of a Transition object and the innerTransitions method for a State object. The command works as shown only when state A1 has one inner transition. If state A1 has more than one transition, you must first find all the inner transitions and then use an array index to access each one:

innerTransitions = sA1.innerTransitions;
label1 = innerTransitions(1).LabelString;
label2 = innerTransitions(2).LabelString;

Access Methods Using Function Notation

As an alternative to dot notation, you can access object methods with standard function call notation. For example, you can use the get method to access the Name property of a Chart object, ch, through one of these commands:

name = ch.get('Name');
name = get(ch,'Name');

If you have array arguments to methods you call, use function notation. This example returns a cell array of character vectors with the names of each chart in the array of Chart objects chartArray:

names = get(chartArray, 'Name');

If, instead, you attempt to use the get command with this dot notation, an error results:

names = chartArray.get('Name');

Related Topics