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 with fixed-point properties

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

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

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

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

`X = ones('like',`

returns
a scalar `p`

)`1`

with the same `numerictype`

,
complexity (real or complex), and `fimath`

as `p`

.

`X = ones(`

returns
an `sz1,...,szN`

,'like',`p`

)`sz1`

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

array of
ones like `p`

.

Using the `b = cast(a,'like',p)`

syntax to
specify data types separately from algorithm code allows you to:

Reuse your algorithm code with different data types.

Keep your algorithm uncluttered with data type specifications and switch statements for different data types.

Improve readability of your algorithm code.

Switch between fixed-point and floating-point data types to compare baselines.

Switch between variations of fixed-point settings without changing the algorithm code.