| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Simulink |
| Contents | Index |
| Learn more about Simulink |
Math Operations
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 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.
You can use the block to assign values to vector, matrix, or multidimensional signals.
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 the indices required by 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 simply assigns the current value of U to Y(Ei), i.e., without first copying Y0 to Y. All of this occurs in a single time step.
The data and initialization ports of the Assignment block accept signals of any data type supported by Simulink software, including fixed-point and enumerated data types. The external indices port accepts any built-in data type, except Boolean data types.
For a discussion on the data types supported by Simulink software, see Data Types Supported by Simulink.

Enter the number of dimensions of the output signal.
Specifies 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.
Define, by dimension, how the elements of the signal are to be indexed. From the list, choose:
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.
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.
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.
Specify how to initialize the output signal. The Initialize output parameter appears only if you select Index vector (port) or Starting index (port) for the Index Option parameter.
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.
Specifies whether to produce a warning or error message if you have not assigned all output elements. Options include:
Error
Warning
None
Specify the time interval between samples. To inherit the sample time, set this parameter to -1. See How to Specify the Sample Time.
Direct Feedthrough | Yes |
Sample Time | Specified by Sample time parameter |
Scalar Expansion | Yes |
Dimensionalized | Yes |
Multidimensionalized | Yes |
Zero Crossing | No |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2010- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |