Inf - Create array of all Inf values - MATLAB (original) (raw)
Create array of all Inf
values
Syntax
Description
[X](#mw%5F4aaa8a5a-52ab-4405-b990-8109114167b1) = Inf
returns the scalar representation of positive infinity. Operations return Inf
when their result is too large to represent as a floating point number, such as1/0
or log(0)
.
For double-precision, Inf
represents numbers larger thanrealmax
. For single-precision, Inf
represents numbers larger than realmax("single")
.
[X](#mw%5F4aaa8a5a-52ab-4405-b990-8109114167b1) = Inf([n](#mw%5F2f12dbe2-ef8f-43b8-a08e-ffb69474a663))
returns an n
-by-n
matrix ofInf
values.
[X](#mw%5F4aaa8a5a-52ab-4405-b990-8109114167b1) = Inf([sz1,...,szN](#mw%5Ffc869e12-a06c-400e-b788-b592b610b4b1))
returns an sz1
-by-...-by-szN
array ofInf
values, where sz1,...,szN
indicate the size of each dimension. For example, Inf(3,4)
returns a 3-by-4 matrix.
[X](#mw%5F4aaa8a5a-52ab-4405-b990-8109114167b1) = Inf([sz](#mw%5F24dbe3ac-d584-4729-98ab-a44f5bcef97e))
returns an array of Inf
values, where the size vectorsz
defines size(X)
. For example,Inf([3 4])
returns a 3-by-4 matrix.
[X](#mw%5F4aaa8a5a-52ab-4405-b990-8109114167b1) = Inf(___,[typename](#mw%5Fc9b67466-41e9-438d-9597-b3f1f90d0b59))
returns an array of Inf
values of data typetypename
, which can be either "single"
or "double"
.
[X](#mw%5F4aaa8a5a-52ab-4405-b990-8109114167b1) = Inf(___,like=[p](#mw%5Fda3f762c-cf6c-44b8-9faa-d55b8dd8b04f))
returns an array of Inf
values of the same data type, sparsity, and complexity (real or complex) as p
. You can specify typename
or like
but not both.
Examples
Create a 3-by-3 matrix of Inf
values.
X = 3×3
Inf Inf Inf Inf Inf Inf Inf Inf Inf
Create a 2-by-3-by-4 array of Inf
values and display its size.
Create an array of Inf
values that is the same size as an existing array.
A = [1 4; 2 5; 3 6]; sz = size(A); X = Inf(sz)
X = 3×2
Inf Inf Inf Inf Inf Inf
It is a common pattern to combine the previous two lines of code into a single line.
Create a 1-by-3 vector of Inf
values whose elements are of type single
.
X = 1×3 single row vector
Inf Inf Inf
You can also specify the output type based on the type of another variable. Create a variable p
of type single
. Then, create a vector of Inf
values with the same size and type as p
.
p = single([1 2 3]); X = Inf(size(p),like=p)
X = 1×3 single row vector
Inf Inf Inf
Input Arguments
Size of square matrix, specified as an integer.
- If
n
is 0, thenX
is an empty matrix. - If
n
is 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, then
X
is an empty array. - If the size of any dimension is negative, then it is treated as 0.
- Beyond the second dimension,
Inf
ignores trailing dimensions of length 1. For example,Inf(3,1,1)
creates a 3-by-1 vector ofInf
values.
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, then
X
is an empty array. - If the size of any dimension is negative, then it is treated as 0.
- Beyond the second dimension,
Inf
ignores trailing dimensions of length 1. For example,Inf([3 1])
creates a 3-by-1 vector ofInf
values.
Data Types: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Data type to create, specified as "double"
or"single"
.
Prototype of array to create, specified as an array.
Data Types: double
| single
Complex Number Support: Yes
Output Arguments
Array of Inf
values, returned as a scalar, vector, matrix, or multidimensional array.
Extended Capabilities
Usage notes and limitations:
- Dimensions must be real, nonnegative, integers.
The Inf
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,X = Inf(3,datatype,'gpuArray')
creates a 3-by-3 GPU array of allInf
values with underlying typedatatype
.
You can specify the underlying typedatatype
as one of these options:'double'
'single'
- 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,X = Inf(3,datatype,'distributed')
creates a 3-by-3 distributed array of allInf
values with underlying typedatatype
.
You can specify the underlying typedatatype
as one of these options:'double'
'single'
- 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 Inf (codistributed) (Parallel Computing Toolbox).
For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced before R2006a