Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Assignment

Assign values to specified elements of 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 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 modelmodel 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.

Data Type Support

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

For more information, see Data Types Supported by Simulink in the Simulink documentation.

Parameters and Dialog Box

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

  • Warning

  • None

Sample time (-1 for inherited)

Specify the time interval between samples. To inherit the sample time, set this parameter to -1. See Specify Sample Time in the Simulink documentation.

Characteristics

Direct Feedthrough

Yes

Sample Time

Specified in the Sample time parameter

Scalar Expansion

Yes

Dimensionalized

Yes

Multidimensionalized

Yes

Zero-Crossing Detection

No

Was this topic helpful?