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

  • The object you move must be visible in the Stateflow® Editor.

    To...You must be viewing...
    Change the position or size of the subchart iconThe parent or container of the subchart
    Change the size of the subchart boundary in the subviewerThe 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 Copy Objects for directions on copying and pasting objects from one container object to another.

Was this topic helpful?