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.
[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.
[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.
[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.
[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
.
Examples
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
Size of first dimension of I
, specified as an integer value.
- If
n
is the only integer input argument, thenI
is a square n-by-n identity matrix. - If
n
is0
, thenI
is an empty matrix. - If
n
is negative, then it is treated as0
.
Data Types: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Size of second dimension of I
, specified as an integer value.
- If
m
is0
, thenI
is an empty matrix. - If
m
is negative, then it is treated as0
.
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.
- If an element of
sz
is0
, thenI
is an empty matrix. - If an element of
sz
is negative, then the element is treated as0
.
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
Identity matrix, returned as a scalar or matrix.
Extended Capabilities
Usage notes and limitations:
typename
must be a built-in MATLAB® numeric type. Does not invoke the staticeye
method for other classes. For example,eye(m, n, 'myclass')
does not invokemyclass.eye(m,n)
.- Size arguments must have a fixed size.
Usage notes and limitations:
typename
must be a built-in MATLAB numeric type. Does not invoke the staticeye
method for other classes. For example,eye(m, n, 'myclass')
does not invokemyclass.eye(m,n)
.- Size arguments must have a fixed size.
The eye
function supports GPU array input with these usage notes and limitations:
- You can specify
typename
as'gpuArray'
. If you specifytypename
as'gpuArray'
, the default underlying type of the array isdouble
.
To create a GPU array with underlying typedatatype
, specify the underlying type as an additional argument beforetypename
. For example,I = eye(3,datatype,'gpuArray')
creates a 3-by-3 GPU identity matrix with underlying typedatatype
.
You can specify the underlying typedatatype
as one of these options:'double'
'single'
'logical'
'int8'
'uint8'
'int16'
'uint16'
'int32'
'uint32'
'int64'
'uint64'
- You can also specify the numeric variable
p
as agpuArray
.
If you specifyp
as agpuArray
, the underlying type of the returned array is the same asp
.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Usage notes and limitations:
- You can specify
typename
as'codistributed'
or'distributed'
. If you specifytypename
as'codistributed'
or'distributed'
, the default underlying type of the returned array isdouble
.
To create a distributed or codistributed array with underlying typedatatype
, specify the underlying type as an additional argument beforetypename
. For example,I = eye(3,datatype,'distributed')
creates a 3-by-3 distributed identity matrix with underlying typedatatype
.
You can specify the underlying typedatatype
as one of these options:'double'
'single'
'logical'
'int8'
'uint8'
'int16'
'uint16'
'int32'
'uint32'
'int64'
'uint64'
- You can also specify
p
as acodistributed
ordistributed
array.
If you specifyp
as acodistributed
ordistributed
array, the underlying type of the returned array is the same asp
. - For additional
codistributed
syntaxes, see eye (codistributed) (Parallel Computing Toolbox).
For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced before R2006a