Assign Signal Values Using Assignment Block in Iterator Subsystem
R2026bThis example shows how to assign values computed in a for loop to specified elements in a signal in Simulink®. You can use a combination of Assignment and For Iterator Subsystem blocks for such value assignment. You can use vector, matrix, or multidimensional signals and do the assignment in a single time step.
In the ex_assignment_block_with_for_iterator model, an Assignment block inside a For Iterator subsystem assigns signal values from a for loop into an output vector signal.

Model Behavior
The For Iterator block creates an index
, which is multiplied by a factor of 3. The Assignment block uses this amplified index value as the input indicated by U. The Assignment block uses the index value
to assign the values to the output vector Y. Both the Assignment and For Iterator blocks use one-based indexing. On the first iteration, 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.
Model Simulation
Simulate the model. The Display block shows the values 3, 6, and 9, which are three times the index values 1, 2, and 3 from the first, second and third iterations, respectively.