Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

eye - Identity matrix

Syntax

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

Description

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

Y = eye(m,n) or Y = eye([m n]) returns an m-by-n matrix with 1's on the diagonal and 0's elsewhere. The size inputs m and n should be nonnegative integers. Negative integers are treated as 0.

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

Y = 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 take the following values: 'double', 'single', 'int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'int64', or 'uint64'.

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

Examples

Return a 2-by-3 matrix of class int8:

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

See Also

magic | ones | zeros

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS