| Contents | Index |
| On this page… |
|---|
How to Move Objects Programmatically |
To move a graphical object programmatically, choose one of these techniques:
| Technique | Example |
|---|---|
Change the Position property of the object directly. | object.Position = [40 40 100 60]); |
Use the set method to change the Position property of the object. | object.set('Position', [40 40 100 60]); |
| set(object, 'Position', [40 40 100 60]); |
In each 1-by-4 array, the first two values are the (x,y) coordinates of the upper left corner of the object. The last two values are the width and height, respectively.
You can adjust the location of a subcharted state as follows:
Open the sf_elevator model.
Get a handle to the root object.
rt = slroot;
Get a handle to the subcharted state Elevator_Manager in the Elevator System chart.
em = rt.find('-isa','Stateflow.State','Name','Elevator_Manager');
Change the chart position of Elevator_Manager.
em.set('Position', [20 250 200 60]);
The following changes occur:
The Elevator_Manager subchart moves to the location (20,250) from the upper left corner of the chart.
The subchart now has a width of 200 and a height of 60.
The object you move must be visible in the Stateflow Editor.
| To... | You must be viewing... |
|---|---|
| Change the position or size of the subchart icon | The parent or container of the subchart |
| Change the size of the subchart boundary in the subviewer | The contents of the subchart |
To switch to a chart-level view programmatically, use these commands:
rt = sfroot;
ch = rt.find('-isa','Stateflow.Chart','Name','name');
ch.view;To view the contents of a subcharted state programmatically, use these commands:
rt = sfroot;
sub = rt.find('-isa','Stateflow.State','Name','name');
sub.view;When you view the contents of a subcharted state, box, or graphical function in the subviewer, you cannot change the position of the subchart boundary programmatically.
For objects in a subcharted state, box, or graphical function, you cannot use the set method to move these objects between different levels of the chart hierarchy. See Copying Objects for directions on copying and pasting objects from one container object to another.
![]() | Accessing Existing Stateflow Objects | Copying Objects | ![]() |

Learn how engineers use Stateflow to model state machines in their Simulink models.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |