Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

Editing Blocks

Copying and Moving Blocks from One Window to Another

As you build your model, you often copy blocks from Simulink block libraries or other libraries or models into your model window. To do this:

  1. Open the appropriate block library or model window.

  2. Drag the block to copy into the target model window. To drag a block, position the cursor over the block, then press and hold down the mouse button. Move the cursor into the target window, then release the mouse button.

You can also drag blocks from the Simulink Library Browser into a model window. See Browsing Block Libraries for more information.

You can also copy blocks by using the Copy and Paste commands from the Edit menu:

  1. Select the block you want to copy.

  2. Choose Copy from the Edit menu.

  3. Make the target model window the active window.

  4. Choose Paste from the Edit menu.

Simulink assigns a name to each copied block. If it is the first block of its type in the model, its name is the same as its name in the source window. For example, if you copy the Gain block from the Math library into your model window, the name of the new block is Gain. If your model already contains a block named Gain, Simulink adds a sequence number to the block name (for example, Gain1, Gain2). You can rename blocks; see Manipulating Block Names.

When you copy a block, the new block inherits all the original block's parameter values.

For more ways to add blocks, see Adding Blocks.

add blocks

Moving Blocks in a Model

To move a single block from one place to another in a model window, drag the block to a new location. Simulink automatically repositions lines connected to the moved block.

To move more than one block, including connecting lines:

  1. Select the blocks and lines. If you need information about how to select more than one block, see Selecting Multiple Objects.

  2. Drag the objects to their new location and release the mouse button.

To move a block, disconnecting lines:

  1. Select the block.

  2. Press the Shift key, then drag the block to its new location and release the mouse button.

You can also move a block by selecting the block and pressing the arrow keys.

Moving blocks from one window to another is similar to copying blocks, except that you hold down the Shift key while you select the blocks.

You can use the Undo command from the Edit menu to remove an added block.

Aligning Blocks

You can use tools to manually align blocks. These tools include a grid snap feature and smart guides that indicate when a block center or port aligns with the center or port of another block. You can also use commands that align a group of blocks automatically (see Aligning, Distributing, and Resizing Groups of Blocks Automatically for details).

Grid Snap.   Simulink uses an invisible five-pixel grid to simplify the alignment of blocks. When you move a block to a new location, the block snaps to the nearest line on the grid. You can display the grid and change its spacing.

To display the grid, enter the following command at the MATLAB command prompt.

set_param('<model name>','showgrid','on')

The default width of the grid is 20 pixels. To change the grid spacing, enter

set_param('<model name>','gridspacing',<number of pixels>)

For example, to change the grid spacing to 25 pixels, enter

set_param('<model name>','gridspacing',25)

For either of the above commands, you can also select the model, then enter gcs instead of <model name>.

Smart Guides.   When you move a block, smart guides appear by default to indicate when the block ports, center, or edges are aligned with the ports, centers, and edges of other blocks in the same diagram. For example, the following figure shows a snapshot of a Gain block that you drag from one position in a diagram to another. The dotted outline indicates the position to which the Gain block has been dragged. The blue smart guides indicate that if you drop the Gain block at this position, its left edge will be aligned with the left edge of the Subsystem block and its output port will be aligned with the input port of the Mux block.

When you drag a block, one of its alignment features, for example, a port, may match more than one alignment feature of another block. In this case, Simulink displays a line for one of the features, using the following precedence order: ports, centers, edges. For example, in the following drag-and-drop snapshot, the Gain block's center aligns with the Subsystem's center and the Gain block's output port aligns with the Mux block's input port. However, because ports take precedence over centers, Simulink draws a guide only for the ports.

You can turn smart guides off or on (the default) by selecting Format > Smart Guides.

Positioning Blocks Programmatically

You can position (and resize) a block programmatically, using its Position parameter. For example, the following command

set_param(gcb, 'Position', [5 5 20 20]);

moves the currently selected block to a location 5 points down and 5 points to the right of the top left corner of the block diagram and sets the block's height and width to 15 points, respectively.

Copying Blocks in a Model

You can copy blocks in a model as follows. While holding down the Ctrl key, select the block with the left mouse button, then drag it to a new location. You can also do this by dragging the block using the right mouse button. Duplicated blocks have the same parameter values as the original blocks. Sequence numbers are added to the new block names.

Deleting Blocks

To delete one or more blocks, select the blocks to be deleted and press the Delete or Backspace key. You can also choose Clear or Cut from the Edit menu. The Cut command writes the blocks into the clipboard, which enables you to paste them into a model. Using the Delete or Backspace key or the Clear command does not enable you to paste the block later.

You can use the Undo command from the Edit menu to replace a deleted block.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS