| Stateflow | ![]() |
www.kxcad.net Home > CAE Software Index > MATLAB Index >
| On this page… |
|---|
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.
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, the following command returns the Type property for a State object represented by the handle s:
stype = s.Type
The following command calls the dialog method of the State object s to open a properties dialog for that state:
s.dialog
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 the final Stateflow chart at the end of Create New Objects in the Chart, the following command returns the string label for state A1's inner transition to its state A11.
label = sA1.innerTransitionsOf.LabelString
The preceding command uses the LabelString property of a Transition object and the innerTransitions method for a State object. It works as shown only because 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, as shown below:
innerTransitions = sA1.innerTransitionsOf label1 = innerTransitions(1).LabelString label2 = innerTransitions(2).LabelString and so on...
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 the following commands:
name = ch.get('Name')
name = get(ch,'Name')
If you have array arguments to methods you call, use function notation. The following example returns a vector of strings 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 the following dot notation, an error results:
names = chartArray.get('Name')
| Quick Start for the Stateflow API | Displaying Properties and Methods | ![]() |
© 1984-2007 The MathWorks, Inc. Terms of Use Patents Trademarks Acknowledgments