eye - Identity matrix - MATLAB (original) (raw)

Syntax

Description

[I](#mw%5Fa7f1ea13-8871-4c75-bea1-b84e56d998cf) = eye returns the scalar1.

[I](#mw%5Fa7f1ea13-8871-4c75-bea1-b84e56d998cf) = eye([n](#btpi59x-1-n)) returns an n-by-n identity matrix with ones on the main diagonal and zeros elsewhere.

example

[I](#mw%5Fa7f1ea13-8871-4c75-bea1-b84e56d998cf) = eye([n](#btpi59x-1-n),[m](#btpi59x-1-m)) returns an n-by-m matrix with ones on the main diagonal and zeros elsewhere.

example

[I](#mw%5Fa7f1ea13-8871-4c75-bea1-b84e56d998cf) = eye([sz](#btpi59x-1-sz)) returns an array with ones on the main diagonal and zeros elsewhere. The size vector, sz, defines size(I). For example,eye([2,3]) returns a 2-by-3 array with ones on the main diagonal and zeros elsewhere.

example

[I](#mw%5Fa7f1ea13-8871-4c75-bea1-b84e56d998cf) = eye(___,[typename](#btpi59x-1-classname)) also specifies the data type (class) of I for any of the previous syntaxes. For example, eye(5,"int8") returns a 5-by-5 identity matrix consisting of 8-bit integers.

example

[I](#mw%5Fa7f1ea13-8871-4c75-bea1-b84e56d998cf) = eye(___,like=[p](#btpi59x-1-p)) specifies that I has the same data type, sparsity, and complexity (real or complex) as the numeric variablep.

example

Examples

collapse all

Create a 4-by-4 identity matrix.

I = 4×4

 1     0     0     0
 0     1     0     0
 0     0     1     0
 0     0     0     1

Create a 2-by-3 identity matrix.

Create a 3-by-1 identity vector.

Create a 3-by-3 identity matrix whose elements are 32-bit unsigned integers.

I = 3×3 uint32 matrix

1 0 0 0 1 0 0 0 1

Create a 2-by-2 identity matrix that is not real valued, but instead is complex like an existing array.

Define a complex vector.

Create an identity matrix that is complex like p.

I = 2×2 complex

1.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 1.0000 + 0.0000i

Define a 5-by-5 sparse matrix.

Create a 5-by-5 identity matrix that is sparse like P.

I = 5×5 sparse double matrix (5 nonzeros) (1,1) 1 (2,2) 1 (3,3) 1 (4,4) 1 (5,5) 1

Define a 2-by-2 matrix of single precision.

Create an identity matrix that is the same size and data type as p.

I = 2×2 single matrix

 1     0
 0     1

Input Arguments

collapse all

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

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

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

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

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

Example: sz = [2 3] defines I as a 2-by-3 matrix.

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

Output class, specified as "double","single", "logical","int8", "uint8","int16", "uint16","int32", "uint32","int64", or "uint64".

Prototype, specified as a numeric variable.

Data Types: double | single | logical | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
Complex Number Support: Yes

Output Arguments

collapse all

Identity matrix, returned as a scalar or matrix.

Extended Capabilities

expand all

Usage notes and limitations:

Usage notes and limitations:

The eye function supports GPU array input with these usage notes and limitations:

For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Usage notes and limitations:

For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).

Version History

Introduced before R2006a