# Identity Matrix

Generate matrix with ones on main diagonal and ground values elsewhere

Since R2021b

Libraries:

## Description

The Identity Matrix block outputs an identity matrix, similar to the MATLAB® `eye` function. The block generates a square or rectangular matrix with ones on the main diagonal and zeros elsewhere.

## Examples

expand all

This example shows how to generate a 3-by-6 unit-diagonal matrix and a 5-by-5 identity matrix using the Identity Matrix block.

## Ports

### Input

expand all

Input signal used to determine dimensions of the output matrix, specified as a scalar, vector, or matrix. When the input signal is an M-by-N matrix, the block generates an M-by-N matrix output with the same sample period as the input. The values in the input matrix are ignored.

#### Dependencies

To enable this port, select the Inherit output port attributes from input port check box.

Data Types: `single` | `double` | `half` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `Boolean` | `fixed point`

### Output

expand all

Identity matrix, specified as a scalar, vector, or matrix.

Data Types: `single` | `double` | `half` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `Boolean` | `fixed point`

## Parameters

expand all

Select this check box for the output port to inherit its dimensions, sample period, and data type from the input port. Otherwise, clear this check box.

#### Programmatic Use

 Block Parameter: `InheritOutputPortAttributes` Type: character vector Values: `'on'` | `'off'` Default: `'off'`

The number of rows and columns in the output matrix. You can specify:

• A positive integer scalar M to create a square M-by-M output.

• A vector of positive integers, [M N], to create an M-by-N output.

#### Dependencies

To enable this parameter, clear the Inherit output port attributes from input port check box.

#### Programmatic Use

 Block Parameter: `OutputDimensions` Type: character vector Values: scalar | two-element vector Default: `'5'`

Specify the output data type for this block. You can select one of these options:

• A rule that inherits a data type, for example, ```Inherit: Inherit via back propagation```. When you select this option, the output data type and scaling matches that of the next downstream block.

• A built-in data type, such as `double`.

• An expression that evaluates to a valid data type, for example, `fixdt(1,16)`.

For help setting data type parameters, display the Data Type Assistant by clicking the button .

#### Programmatic Use

 Block Parameter: `OutDataTypeStr` Type: character vector Values: ```'Inherit: Inherit via back propagation'``` | `'double'` | `'single'` | `'half'` | `'int8'` | `'uint8'` | `'int16'` | `'uint16'` | `'int32'` | `'uint32'` | `'int64'` | `'uint64'` | | `'fixdt(1,16,0)'` | ```''``` Default: `'double'`

Select how you would like to specify the data type properties of the Output data type. You can choose:

• `Inherit` — Specify a rule for inheriting a data type, for example, `Inherit: Same as input`.

• `Built in`— Specify a built-in data type, for example, `double`.

• `Fixed point` — Specify the fixed-point attributes of the data type.

• `Expression` — Specify an expression that evaluates to a valid data type, for example, `fixdt(1,16)`.

Specify whether the fixed-point data is signed or unsigned. `Signed` data can represent positive and negative values, but `Unsigned` data represents positive values only. For more information, see Specify Data Types Using Data Type Assistant.

Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors. For more information, see Specify Data Types Using Data Type Assistant.

#### Dependencies

To enable this parameter, set Mode to ```Fixed point```

Specify the bit size of the word that holds the quantized integer as a positive integer from 2 to 128. For more information, see Specify Data Types Using Data Type Assistant.

#### Dependencies

To enable this parameter, set Mode to ```Fixed point```.

Specify the fraction length of the fixed-point data type as a positive or negative integer scalar.

#### Dependencies

To enable this parameter, set Mode to ```Fixed point``` and Scaling to ```Binary point```.

Select the data type override mode for this signal. You can select:

• `Inherit` — Inherits the data type override setting specified for the model.

• `Off` — Ignores the data type override setting specified for the model and uses the fixed-point data type you specify.

#### Dependencies

To enable this parameter, set Mode to ```Built in``` or `Fixed point`. For more information, see Specify Data Types Using Data Type Assistant.

The discrete sample period of the output, specified as a real-valued scalar.

#### Dependencies

To enable this parameter, clear the Inherit output port attributes from input port check box.

#### Programmatic Use

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

## Block Characteristics

 Data Types `Boolean` | `double` | `fixed point` | `half` | `integer` | `single` Direct Feedthrough `no` Multidimensional Signals `no` Variable-Size Signals `no` Zero-Crossing Detection `no`

## Version History

Introduced in R2021b

expand all