Simulink Reference    
Assignment

Assign values to specified elements of a signal

Library

Math Operations

Description


The Assignment block assigns values to specified elements of the signal connected to its U1 port. You can specify the indices of the elements to be assigned values either by entering the indices in the block's dialog box or by connecting an external indices source or sources to the block. You specify the values to be assigned to the signal at U1 by connecting a values signal to the Assignment block's U2 port. The block replaces the specified elements of U1 with elements from U2, leaving unassigned elements unchanged, and outputs the result.

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

Assigning Values to a Vector Signal

To assign values to a scalar or vector signal, set the block's Input Type parameter to Vector. The block's dialog box displays a Source of element indices parameter. You can specify the indices source as Internal or External. If you select Internal, the block dialog box displays an Elements field. Use this field to enter the element indices. If you specify External as the source of element indices, the block displays an input port named E. Connect an external index source to this port. The index source can specify any of the following values as indices:

The width of the values signal connected to U2 must be the same as the width of the indices vector. For example, if the indices vector contains two indices, U2 must be a two-element vector of values. The block assigns the first element of U2 to the element of U1 specified by the first index, the second element of U2 to the U1 element specified by the second index, and so on.

Assigning Values to a Matrix Signal

To assign values to a matrix signal, set the Input Type parameter to Matrix. If you specify the Input Type of the Assignment block as Matrix, the block's dialog box displays a Source of row indices parameter and a Source of column indices parameter. You can specify either or both of these parameters as Internal or External. If you specify the row and/or column index source as internal, the block displays a Rows and/or Columns field. Enter the row or column indices of the elements of U1 to be assigned values into the corresponding field. If you specify the row and/or column index source as External, the block displays an input port labeled R and/or an input port labeled C. Connect an external source of indices to each indices port.

A row or column indices source can have any of the following values:

The block assigns values from U2 to the specified elements of U1 in column-major order. In particular, the block assigns the first element of the first row of U2 to the first specified element in the first specified row in U1. It assigns the second element of the first row of U2 to the second specified element of the first specified row of U1, and so on.

To enable all specified elements to be assigned values, U2 must be an N-by-M matrix where N is the width of the row indices vector and M is the width of the column indices vector. For example, suppose that you specify a vector of row indices of size 2 and a vector of column indices of size 4. Then U2 must be a 2-by-4 matrix signal.

When determining the dimensions of U2, count a single row or column index as a vector of size 1 and -1 as equivalent to a vector of indices of the same width as the row or dimension size of U1. For example, suppose your row and column index sources specify a single row index and two column indices. Then U2 must by a 1-by-2 matrix.

Iterated Assignment

You can use the Assignment block to assign values computed in an iterator (For or While) loop to a vector or matrix signal. To do this, use an iterator block to generate the indices required by the Assignment block (or two iterator blocks if you need to compute row and column indices separately). For example, the following model uses a For block to a create a vector signal each of whose elements equals 3*i where i is the index of the element.

Data Type Support

The Assignment block accepts signals of any data type, including fixed-point data types.

Parameters and Dialog Box

Input Type
You can select either Vector or Matrix input. If you select Vector, the Source of element indices field appears. If you select Matrix, the Source of row indices and Source of column indices fields appear.
Source of element indices
You can specify either Internal (the default) or External as the source for the indices of the elements to be assigned values. If you select Internal, the block dialog box displays an Elements field (see following). Use this field to enter the element indices. If you select External, the block displays an input port labeled E. Connect the external index source to this port.
Elements
This field appears only if you selected Internal for the Source of element indices field. It specifies the indices of elements in U1 to be replaced by elements in U2. The value of this parameter can be -1, a positive integer specifying a single index, or a vector of positive integers specifying a set of indices (e.g., [1,3,5,6]).
Source of row indices
Either Internal (the default) or External. If you select Internal, the Rows field appears. Enter the indices of the rows to be assigned values in this field. If you select External, the block displays an input port labeled R. Connect an external source of row indices to this port.
Rows
This field appears only if you select Internal for the Source of row indices field. Valid values are -1 (all rows), a single row index, or a vector of row indices (e.g., [1,3,5,6]).
Source of column indices
Either Internal (the default) or External. If you select Internal, the Columns field appears. Enter the indices of the columns to be assigned values in this field. If you select External, the block displays an input port labeled C. Connect an external source of column indices to this port.
Columns
This field appears only if you selected internal for the Source of column indices field. Valid values are -1 (all columns), a single column index, or a vector of column indices (e.g., [1,3,5,6]).

Characteristics

Direct Feedthrough
Yes
Sample Time
Inherited from driving block
Scalar Expansion
No
Dimensionalized
Yes
Zero Crossing
No


  Assertion Backlash