Assignment

Assign values to specified elements of signal

  • Library:
  • Simulink / Math Operations

    HDL Coder / Math Operations

Description

The Assignment block assigns values to specified elements of the signal. You 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, 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. To enable an external index port, in the corresponding row of the table, set Index Option to Index vector (port).

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:

RowIndex OptionIndex
1Assign all 
2Index vector (dialog)[1 3 5]
3Starting index (dialog)4
4Starting index (port) 
5Index vector (port) 

The assigned values are 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.

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.

Assignment Block in Conditional Subsystem

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

However, if you select the Ensure outport is virtual check box for the conditional subsystem Outport block, such cases are supported and partial writes to arrays using Assignment blocks are possible.

Ports

Input

expand all

The initialization signal for the output signal. If an element is not assigned another value, then the value of the output element matches this input signal value.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | fixed point | Boolean | enumerated | bus

Value assigned to the output element when specified.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | fixed point | Boolean | enumerated | bus

External port specifying an index for the assignment of the corresponding output element.

Dependencies

To enable an external index port, in the corresponding row of the Index Option table, set Index Option to Index vector (port) or Starting index (port).

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | fixed point | enumerated

Output

expand all

The output signal with assigned values for the specified elements.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | fixed point | enumerated | bus

Parameters

expand all

Enter the number of dimensions of the output signal.

Command-Line Information

Parameter: NumberOfDimensions
Type: character vector
Values: integer
Default: '1'

Select the indexing mode. If One-based is selected, an index of 1 specifies the first element of the input vector. If Zero-based is selected, an index of 0 specifies the first element of the input vector.

Command-Line Information

Parameter: IndexMode
Type: character vector
Values: 'Zero-based' | 'One-based'
Default: 'One-based'

Define, by dimension, how the elements of the signal are to be indexed. From the list, select:

Menu ItemAction
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 one of these values for the Initialize output (Y) parameter:

  • 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.

Command-Line Information

Parameter: IndexOptionArray
Type: character vector
Values: 'Assign all' | 'Index vector (dialog)' | 'Index option (port)' | 'Starting index (dialog)' | 'Starting index (port)'
Default: 'Index vector (dialog)'

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.

Command-Line Information

Parameter: IndexParamArray
Type: character vector
Values: cell array
Default: '{ }'

Enter the width of the block output signal.

Dependencies

To enable this column, select Specify size for each dimension in table for the Initialize output (Y) parameter.

Command-Line Information

Parameter: OutputSizeArray
Type: character vector
Values: cell array
Default: '{ }'

Specify how to initialize the output signal.

  • Initialize using input port <Y0> – Signal at the input port Y0 initializes the output.

  • Specify size for each dimension in table – 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.

Dependency

Enabled when you set Index Option to Index vector (port) or Starting index (port).

Command-Line Information

Parameter: OutputInitialize
Type: character vector
Values: 'Initialize using input port <Y0>' | 'Specify size for each dimension in table'
Default: 'Initialize using input port <Y0>'

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.

Command-Line Information

Parameter: DiagnosticForDimensions
Type: character vector
Values: 'Error' | 'Warning' | 'None'
Default: 'None'

Specify the sample time as a value other than -1. For more information, see Specify Sample Time.

Dependencies

This parameter is not visible unless it is explicitly set to a value other than -1. To learn more, see Blocks for Which Sample Time Is Not Recommended.

Programmatic Use

Block Parameter: SampleTime
Type: character vector
Values: scalar or vector
Default: '-1'

Block Characteristics

Data Types

Boolean | double | enumerated | fixed point | integer | single

Direct Feedthrough

yes

Multidimensional Signals

yes

Variable-Size Signals

yes

Zero-Crossing Detection

no

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Introduced before R2006a