Documentation

This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

Assignment

Assign values to specified elements of signal

Math Operations

Description

The Assignment block assigns values to specified elements of the signal. You can specify the indices of the elements to be assigned values either by entering the indices in the block dialog box or by connecting an external indices source or sources to the block. The signal at the block data port, labeled U, specifies values to be assigned to Y. The block replaces the specified elements of Y with elements from the data signal.

Based on the value you enter for the Number of output dimensions parameter, a table of index options is displayed. Each row of the table corresponds to one of the output dimensions in Number of output dimensions. For each dimension, you can define the elements of the signal to work with. Specify a vector signal as a 1-D signal and a matrix signal as a 2-D signal. When you configure the Assignment block for multidimensional signal operations, the block icon changes.

For example, assume a 5-D signal with a one-based index mode. The table in the Assignment block dialog changes to include one row for each dimension. If you define each dimension with the following entries:

• 1

Index Option, select ```Assign all```

• 2

Index Option, select ```Index vector (dialog)```

Index, enter `[1 3 5]`

• 3

Index Option, select ```Starting index (dialog)```

Index, enter `4`

• 4

Index Option, select ```Starting index (port)```

• 5

Index Option, select ```Index vector (port)```

The assigned values will be `Y(1:end,[1 3 5],4:3+size(U,3),Idx4:Idx4+size(U,4)-1,Idx5)=U`, where `Idx4` and `Idx5` are the input ports for dimensions 4 and 5.

The Assignment block's data port is labeled U. The rest of this section refers to the data port as U to simplify the explanation of the block's usage.

When using the Assignment block in Normal mode, Simulink® initializes block outputs to zero even if the model does not explicitly initialize them. In Accelerator mode, Simulink converts the model into an S-Function. This involves code generation. The code generated may not do implicit initialization of block outputs. In such cases, you must explicitly initialize the model outputs.

You can use the block to assign values to vector, matrix, or multidimensional signals.

You can use an array of buses as an input signal to an Assignment block. For details about defining and using an array of buses, see Combine Buses into an Array of Buses.

Iterated Assignment

You can use the Assignment block to assign values computed in a For or While Iterator loop to successive elements of a vector, matrix, or multidimensional signal in a single time step. For example, the following model uses a For Iterator block to create a vector signal each of whose elements equals 3*i where i is the index of the element.

Iterated assignment uses an iterator (For or While) block to generate indices for the Assignment block. On the first iteration of an iterated assignment, the Assignment block copies the first input (Y0) to the output (Y) and assigns the second input (U) to the output Y(E1). On successive iterations, the Assignment block assigns the current value of U to Y(Ei), that is, without first copying Y0 to Y. These actions occur in a single time step.

Assignment Block in Conditional Subsystem

If you place an Assignment block in a conditional subsystem block, a signal buffer can be inserted in many cases, and merging of signals from Assignment blocks with partial writes can cause an error.

However, if you select the Ensure outport is virtual check box for the conditional subsystem Outport block, such cases are supported and partial writes to arrays using Assignment blocks are possible.

Data Type Support

The data and initialization ports of the Assignment block accept signals of any data type that Simulink supports, including fixed-point, enumerated, and nonvirtual bus data types. The external indices port accepts any built-in data type, except Boolean data types.

Parameters

Number of output dimensions

Enter the number of dimensions of the output signal.

Index mode

Select the indexing mode: `One-based` or `Zero-based`. If `One-based` is selected, an index of 1 specifies the first element of the input vector, 2, the second element, and so on. If `Zero-based` is selected, an index of 0 specifies the first element of the input vector, 1, the second element, and so on.

Index Option

Define, by dimension, how the elements of the signal are to be indexed. From the list, select:

• `Assign all`

This is the default. All elements are assigned.

• `Index vector (dialog)`

Enables the Index column. Enter the indices of elements.

• `Index vector (port)`

Disables the Index column. The index port defines the indices of elements.

• `Starting index (dialog)`

Enables the Index column. Enter the starting index of the range of elements to be assigned values.

• `Starting index (port)`

Disables the Index column. The index port defines the starting index of the range of elements to be assigned values.

If you choose `Index vector (port)` or ```Starting index (port)``` for any dimension in the table, you can specify the value for the Initialize output (Y) parameter to be one of the following:

• `Initialize using input port <Y0>`

• `Specify size for each dimension in table`

Otherwise, Y0 always initializes output port Y.

The Index and Output Size columns are displayed as relevant.

Index

If the Index Option is ```Index vector (dialog)```, enter the index of each element you are interested in.

If the Index Option is ```Starting index (dialog)```, enter the starting index of the range of elements to be selected. The number of elements from the starting point is determined by the size of this dimension at U.

Output Size

Enter the width of the block output signal. If you select ```Specify size for each dimension in table``` for the Initialize output (Y) parameter, this column is enabled.

Initialize output (Y)

Specify how to initialize the output signal. The Initialize output parameter appears when you set Index Option to ```Index vector (port)``` or `Starting index (port)`.

• `Initialize using input port <Y0>`

The signal at the input port Y0 initializes the output.

• `Specify size for each dimension in table`

The block requires you to specify the width of the block's output signal in the Output Size parameter. If the output has unassigned elements, the value of those elements is undefined.

Action if any output element is not assigned

Specify whether to produce a warning or error if you have not assigned all output elements. Options include:

• `Error` — Simulink software terminates the simulation and displays an error.

• `Warning` — Simulink software displays a warning and continues the simulation.

• `None` — Simulink software takes no action.

Sample time
 Note:   This parameter is not visible in the block dialog box unless it is explicitly set to a value other than `-1`. To learn more, see Blocks for Which Sample Time Is Not Recommended.

Characteristics

 Data Types Double | Single | Boolean | Base Integer | Fixed-Point | Enumerated Sample Time Inherited from driving block Direct Feedthrough Yes Multidimensional Signals Yes Variable-Size Signals Yes Zero-Crossing Detection No Code Generation Yes