Simulink Reference Previous page   Next Page
Assignment

Assign values to specified elements of a signal

Library

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's dialog box or by connecting an external indices source or sources to the block. The signal at the block's data port, labeled U2 in most modes, specifies values to be assigned to Y. The block replaces the specified elements of Y with elements from the data signal, leaving unassigned elements unchanged from their initial values. If the assignment indices source is internal or is external and the Initialize using input option is selected, the Assignment block uses the signal at the block's initialization port, labeled U1, to initialize the elements of the output signal before assigning them values from U2.

You can use the block to assign values to 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. Use Index mode to specify whether 0 or 1 indicates the first element of Y.

The index source can specify any of the following values as indices:

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 Y 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:

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 or matrix 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 the indices required by the Assignment block. On the first iteration of an iterated assignment, the Assignment block copies the first input (U1) to the output (Y) and assigns the second input (U2) to the output Y(E0). On successive iterations, the Assignment block simply assigns the current value of U2 to Y(Ei), i.e., without first copying U1 to Y. All of this occurs in a single time step.

Data Type Support

The data and intitialization ports of the Assignment block accept signals of any data type supported by Simulink, including fixed-point data types. The external indices port accepts any data type, except boolean and fixed-point data types.

For a discussion on the data types supported by Simulink, refer to Data Types Supported by Simulink in the Using Simulink documentation.

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.
Index mode
Specifies whether the index corresponding to the first element of a vector or the first row or column of a matrix is 0 or 1.
Use index as starting value
Specifies that the value in the Elements (or Row or Column) field is the starting index of a range of elements (or rows or columns).
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 Y to be assigned values from elements in U2. The value of this parameter can be -1, a nonnegative integer specifying a single index, or a vector of nonnegative 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]).
Output (Y)
This control appears only if the source of assignment indices is external or, in the case of matrix assignment, the source of either the row or column indices, or both, is external. The options are Initialize using input (U1) (the default) or Specify required dimensions. The first option causes the Assignment block to display an initialization port labeled U1 and to use the signal at this port to initialize the output signal (Y) before assigning it values from the data port (U2) as specified by the external indices signal (E). The second option does not initialize Y before assigning values from the block's data input port (labeled U1 in this case) to it. This option requires that the block's U1 and E inputs assign values to every element of Y. Further, it requires that you specify the dimensions of the output signal (see next control).
Output dimensions
This control appears only if you specify the Specify required dimensions option of the Output (Y) control. It specifies the dimensions of the Assignment block's output signal.
Diagnostic if not all required dimensions are populated
This control appears only if you specify the Specify required dimensions option of the Output (Y) control. It specifies the diagnostic action that Simulink should take if the block's data (U1) and external indices (E) inputs do not assign a value to every element of the block's output (Y). The options are to display an error message and halt the simulation (Error), display a warning message (Warning) and continue the simulation, or continue the simulation (None). If you choose Warning or None, the values of the unassigned elements of the output are undefined.
Sample time (-1 for inherited)
Specify the time interval between samples. To inherit the sample time, set this parameter to -1. See Specifying Sample Time in the online documentation for more information.

Characteristics

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


Previous page  Assertion Backlash Next page

© 1994-2005 The MathWorks, Inc.