Main Content

Inf

Create array of allInfvalues

Description

X = Infreturns the scalar representation of positive infinity. Operations returnInfwhen their result is too large to represent as a floating point number, such as1/0orlog(0).

For double-precision,Infrepresents numbers larger thanrealmax. For single-precision,Infrepresents numbers larger thanrealmax('single').

example

X = Inf(n)returns ann-by-nmatrix ofInfvalues.

example

X = Inf(sz1,...,szN)returns ansz1-by-...-by-szNarray ofInfvalues, wheresz1,...,szNindicate the size of each dimension. For example,Inf(3,4)returns a 3-by-4 matrix.

example

X = Inf(sz)returns an array ofInfvalues, where the size vectorszdefinessize(X). For example,Inf([3 4])returns a 3-by-4 matrix.

example

X = Inf(___,typename)returns an array ofInfvalues of data typetypename, which can be either'single'or'double'.

example

X = Inf(___,'like',p)returns an array ofInfvalues of the same data type, sparsity, and complexity (real or complex) asp. You can specifytypenameor'like'but not both.

Examples

collapse all

Create a 3-by-3 matrix ofInfvalues.

X = Inf(3)
X =3×3Inf Inf Inf Inf Inf Inf Inf Inf Inf

Create a 2-by-3-by-4 array ofInfvalues and display its size.

X = Inf(2,3,4); size(X)
ans =1×32 3 4

Create an array ofInfvalues that is the same size as an existing array.

A = [1 4; 2 5; 3 6]; sz = size(A); X = Inf(sz)
X =3×2Inf Inf Inf Inf Inf Inf

It is a common pattern to combine the previous two lines of code into a single line.

X = Inf(size(A));

Create a 1-by-3 vector ofInfvalues whose elements are of typesingle.

X = Inf(1,3,'single')
X =1x3 single row vectorInf Inf Inf

You can also specify the output type based on the type of another variable. Create a variablepof typesingle. Then, create a vector ofInfvalues with the same size and type asp.

p = single([1 2 3]); X = Inf(size(p),'like',p)
X =1x3 single row vectorInf Inf Inf

Input Arguments

collapse all

Size of square matrix, specified as an integer.

  • Ifnis 0, thenXis an empty matrix.

  • Ifnis negative, then it is treated as 0.

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

Size of each dimension in a list, specified as separate integer arguments.

  • If the size of any dimension is 0, thenXis an empty array.

  • If the size of any dimension is negative, then it is treated as 0.

  • Beyond the second dimension,Inf忽略了后的尺寸的长度是1。对进行了le,Inf(3,1,1)creates a 3-by-1 vector ofInfvalues.

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

Size of each dimension in a vector, specified as a row vector of integers.

  • If the size of any dimension is 0, thenXis an empty array.

  • If the size of any dimension is negative, then it is treated as 0.

  • Beyond the second dimension,Inf忽略了后的尺寸的长度是1。对进行了le,Inf([3 1])creates a 3-by-1 vector ofInfvalues.

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

数据类型来创建、specified as'double'or'single'.

Prototype of array to create, specified as an array.

Data Types:double|single
Complex Number Support:Yes

Extended Capabilities

Version History

Introduced before R2006a