eye

Create identity matrix with fixed-point properties

Syntax

``I = eye('like',p)``
``I = eye(n,'like',p)``
``I = eye(n,m,'like',p)``
``I = eye(sz,'like',p)``

Description

````I = eye('like',p)` returns the scalar 1 with the same fixed-point properties and complexity (real or complex) as the prototype argument, `p`. The output, `I`, contains the same `numerictype` and `fimath` properties as `p`.```

example

````I = eye(n,'like',p)` returns an `n`-by-`n` identity matrix like `p`, with ones on the main diagonal and zeros elsewhere.```

example

````I = eye(n,m,'like',p)` returns an `n`-by-`m` identity matrix like `p`.```
````I = eye(sz,'like',p)` returns an array like `p`, where the size vector, `sz`, defines `size(I)`.```

Examples

collapse all

Create a prototype `fi` object, `p`.

`p = fi([],1,16,14);`

Create a 3-by-4 identity matrix with the same fixed-point properties as `p`.

`I = eye(3,4,'like',p)`
```I = 1 0 0 0 0 1 0 0 0 0 1 0 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 14 ```

Create a signed `fi` object with word length of 16, fraction length of 15 and `OverflowAction` set to `Wrap`.

```format long p = fi([],1,16,15,'OverflowAction','Wrap');```

Create a 2-by-2 identity matrix with the same `numerictype` properties as `p`.

`X = eye(2,'like',p)`
```X = 0.999969482421875 0 0 0.999969482421875 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 15 RoundingMethod: Nearest OverflowAction: Wrap ProductMode: FullPrecision SumMode: FullPrecision ```

1 cannot be represented by the data type of `p`, so the value saturates. The output `fi` object `X` has the same `numerictype` and `fimath` properties as `p`.

Input Arguments

collapse all

Size of first dimension of `I`, specified as an integer value.

• If `n` is the only integer input argument, then `I` is a square `n`-by-`n` identity matrix.

• If `n` is `0`, then `I` is an empty matrix.

• If `n` is negative, then it is treated as `0`.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64`

Size of second dimension of `I`, specified as an integer value.

• If `m` is `0`, then `I` is an empty matrix.

• If `m` is negative, then it is treated as `0`.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64`

Size of `I`, specified as a row vector of no more than two integer values.

• If an element of `sz` is `0`, then `I` is an empty matrix.

• If an element of `sz` is negative, then the element is treated as `0`.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64`

Prototype, specified as a `fi` object or numeric variable.

If the value 1 overflows the numeric type of `p`, the output saturates regardless of the specified `OverflowAction` property of the attached `fimath`. All subsequent operations performed on the output obey the rules of the attached `fimath`.

Data Types: `fi` | `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64`

Tips

Using the `b = cast(a,'like',p)` syntax to specify data types separately from algorithm code allows you to:

• Reuse your algorithm code with different data types.

• Keep your algorithm uncluttered with data type specifications and switch statements for different data types.

• Improve readability of your algorithm code.

• Switch between fixed-point and floating-point data types to compare baselines.

• Switch between variations of fixed-point settings without changing the algorithm code.

Version History

Introduced in R2015a