MATLAB Function Reference  eye

Identity matrix

Syntax

• ```Y  =  eye(n)
Y  =  eye(m,n)
Y  =  eye(size(A))
eye(m, n, classname)
eye([m,n],classname)
```

Description

```Y = eye(n) ``` returns the `n`-by-`n` identity matrix.

```Y = eye(m,n) or eye([m n]) ``` returns an `m`-by-`n` matrix with `1`'s on the diagonal and `0`'s elsewhere.

```Y = eye(size(A)) ``` returns an identity matrix the same size as `A`.

`eye(m, n, classname)` or `eye([m,n],classname)` is an m-by-n matrix with 1's of class `classname` on the diagonal and zeros of class `classname` elsewhere. `classname` is a string specifying the data type of the output. `classname` can have the following values: `'double'`, `'single'`, `'int8'`, `'uint8'`, `'int16'`, `'uint16'`, `'int32'`, `'uint32'`, `'int64'`, or `'uint64'`.

Example:

• ```x = eye(2,3,'int8');
```

Limitations

The identity matrix is not defined for higher-dimensional arrays. The assignment `y = eye([2,3,4])` results in an error.

See Also

`ones`, `rand`, `randn`, `zeros`

© 1994-2005 The MathWorks, Inc.