Documentation

Move Graphical Objects

How to Move Objects Programmatically

To move a graphical object programmatically, choose one of these techniques:

TechniqueExample

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.

    Note:   These programmatic techniques work only for objects that have the Position property.

Move a Subcharted State

You can adjust the location of a subcharted state as follows:

  1. Open the sf_elevatorsf_elevator model.

  2. Get a handle to the root object.

    rt = slroot;
  3. Get a handle to the subcharted state Elevator_Manager in the Elevator System chart.

    em = rt.find('-isa','Stateflow.State','Name','Elevator_Manager');
    
  4. 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.

Rules for Moving Objects Programmatically

  • You cannot change the position of a subchart boundary in the subviewer 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 Copy Objects for directions on copying and pasting objects from one container object to another.

Was this topic helpful?