Documentation

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 dialog box or by connecting an external indices source or sources to the block. The signal at the block 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 theNumber of output dimensionsparameter, a table of index options is displayed. Each row of the table corresponds to one of the output dimensions inNumber 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中,选择Assign all

  • 2

    Index Option中,选择Index vector (dialog)

    Index, enter[1 3 5]

  • 3

    Index Option中,选择Starting index (dialog)

    Index, enter4

  • 4

    Index Option中,选择Starting index (port)

  • 5

    Index Option中,选择Index vector (port)

The assigned values will beY(1:end,[1 3 5],4:3+size(U,3),Idx4:Idx4+size(U,4)-1,Idx5)=U, whereIdx4andIdx5are 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, seeCombine 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 followingmodeluses 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.

Assignment Block in Conditional Subsystem

If you place anAssignmentblock in a conditional subsystem block, a signal buffer can be inserted in many cases, and merging of signals fromAssignmentblocks with partial writes can cause an error.

However, if you select the在sure outport is virtualcheck box for the conditional subsystemOutportblock, such cases are supported and partial writes to arrays usingAssignmentblocks are possible.

Data Type Support

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

For more information, seeData Types Supported by Simulinkin the Simulink documentation.

Parameters

Number of output dimensions

在ter the number of dimensions of the output signal.

Index mode

Select the indexing mode:One-basedorZero-based. IfOne-based被选中时,索引1指定第一个避署ment of the input vector, 2, the second element, and so on. IfZero-basedis 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)

    在ables theIndex列。在ter the indices of elements.

  • Index vector (port)

    Disables theIndex列。The index port defines the indices of elements.

  • Starting index (dialog)

    在ables theIndex列。在ter the starting index of the range of elements to be assigned values.

  • Starting index (port)

    Disables theIndex列。The index port defines the starting index of the range of elements to be assigned values.

If you chooseIndex vector (port)orStarting index (port)for any dimension in the table, you can specify the value for theInitialize output (Y)parameter to be one of the following:

  • Initialize using input port

  • Specify size for each dimension in table

Otherwise, Y0 always initializes output port Y.

TheIndexandOutput Sizecolumns are displayed as relevant.

Index

If theIndex OptionisIndex vector (dialog), enter the index of each element you are interested in.

If theIndex OptionisStarting 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

在ter the width of the block output signal. If you selectSpecify size for each dimension in tablefor theInitialize output (Y)parameter, this column is enabled.

Initialize output (Y)

Specify how to initialize the output signal. TheInitialize outputparameter appears when you setIndex OptiontoIndex vector (port)orStarting index (port).

  • Initialize using input port

    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 theOutput Sizeparameter. 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— Simulink software terminates the simulation and displays an error.

  • Warning— Simulink software displays a warning and continues the simulation.

  • None— Simulink software takes no action.

Sample time

Note

This parameter is not visible in the block dialog box unless it is explicitly set to a value other than-1. To learn more, seeBlocks for Which Sample Time Is Not Recommended.

Characteristics

Data Types

Double | Single | Boolean | Base Integer | Fixed-Point | Enumerated

Sample Time

Inherited from driving block

Direct Feedthrough

Yes

Multidimensional Signals

Yes

Variable-Size Signals

Yes

Zero-Crossing Detection

No

Code Generation

Yes

Introduced before R2006a

Was this topic helpful?