Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Create array of all ones

`X = ones`

`X = ones(n)`

`X = ones(sz1,...,szN)`

`X = ones(sz)`

`X = ones(classname)`

`X = ones(n,classname)`

`X = ones(sz1,...,szN,classname)`

`X = ones(sz,classname)`

`X = ones('like',p)`

`X = ones(n,'like',p)`

`X = ones(sz1,...,szN,'like',p)`

`X = ones(sz,'like',p)`

`X = ones`

returns the scalar `1`

.

`X = ones(`

returns
an `sz1,...,szN`

)`sz1`

-by-...-by-`szN`

array of
ones where `sz1,...,szN`

indicates the size of each
dimension. For example, `ones(2,3)`

returns a 2-by-3
array of ones.

`X = ones(`

returns
a scalar `classname`

)`1`

where `classname`

specifies
the data type. For example, `ones('int8')`

returns
a scalar, 8-bit integer `1`

.

`X = ones(`

returns
an `sz1,...,szN`

,`classname`

)`sz1`

-by-...-by-`szN`

array of
ones of data type `classname`

.

`X = ones('like',`

returns
a scalar `p`

)`1`

with the same data type, sparsity, and
complexity (real or complex) as the numeric variable, `p`

.

`X = ones(`

returns
an `sz1,...,szN`

,'like',`p`

)`sz1`

-by-...-by-`szN`

array of
ones like `p`

.

Was this topic helpful?