# ones

Create quaternion array with real parts set to one and imaginary parts set to zero

## Syntax

``quatOnes = ones('quaternion')``
``quatOnes = ones(n,'quaternion')``
``quatOnes = ones(sz,'quaternion')``
``quatOnes = ones(sz1,...,szN,'quaternion')``
``quatOnes = ones(___,'like',prototype,'quaternion')``

## Description

example

````quatOnes = ones('quaternion')` returns a scalar quaternion with the real part set to 1 and the imaginary parts set to 0.Given a quaternion of the form $Q=a+b\text{i}+c\text{j}+d\text{k}$, a quaternion one is defined as $Q=1+0\text{i}+0\text{j}+0\text{k}$.```

example

````quatOnes = ones(n,'quaternion')` returns an `n`-by-`n` quaternion matrix with the real parts set to 1 and the imaginary parts set to 0.```

example

````quatOnes = ones(sz,'quaternion')` returns an array of quaternion ones where the size vector, `sz`, defines `size(qOnes)`.Example: `ones([1,4,2],'quaternion')` returns a 1-by-4-by-2 array of quaternions with the real parts set to `1` and the imaginary parts set to `0`.```

example

````quatOnes = ones(sz1,...,szN,'quaternion')` returns a `sz1`-by-...-by-`szN` array of ones where `sz1,…,szN` indicates the size of each dimension.```

example

````quatOnes = ones(___,'like',prototype,'quaternion')` specifies the underlying class of the returned quaternion array to be the same as the underlying class of the quaternion prototype.```

## Examples

collapse all

Create a quaternion scalar one.

`quatOnes = ones('quaternion')`
```quatOnes = quaternion 1 + 0i + 0j + 0k ```

Create an n-by-n matrix of quaternion ones.

```n = 3; quatOnes = ones(n,'quaternion')```
```quatOnes = 3x3 quaternion array 1 + 0i + 0j + 0k 1 + 0i + 0j + 0k 1 + 0i + 0j + 0k 1 + 0i + 0j + 0k 1 + 0i + 0j + 0k 1 + 0i + 0j + 0k 1 + 0i + 0j + 0k 1 + 0i + 0j + 0k 1 + 0i + 0j + 0k ```

Create a multidimensional array of quaternion ones by defining array dimensions in order. In this example, you create a 3-by-1-by-2 array. You can specify dimensions using a row vector or comma-separated integers. Specify the dimensions using a row vector and display the results:

```dims = [3,1,2]; quatOnesSyntax1 = ones(dims,'quaternion')```
```quatOnesSyntax1 = 3x1x2 quaternion array quatOnesSyntax1(:,:,1) = 1 + 0i + 0j + 0k 1 + 0i + 0j + 0k 1 + 0i + 0j + 0k quatOnesSyntax1(:,:,2) = 1 + 0i + 0j + 0k 1 + 0i + 0j + 0k 1 + 0i + 0j + 0k ```

Specify the dimensions using comma-separated integers, and then verify the equivalency of the two syntaxes:

```quatOnesSyntax2 = ones(3,1,2,'quaternion'); isequal(quatOnesSyntax1,quatOnesSyntax2)```
```ans = logical 1 ```

A quaternion is a four-part hyper-complex number used in three-dimensional rotations and orientations. You can specify the underlying data type of the parts as `single` or `double`. The default is `double`.

Create a quaternion array of ones with the underlying data type set to `single`.

`quatOnes = ones(2,'like',single(1),'quaternion')`
```quatOnes = 2x2 quaternion array 1 + 0i + 0j + 0k 1 + 0i + 0j + 0k 1 + 0i + 0j + 0k 1 + 0i + 0j + 0k ```

Verify the underlying class using the `classUnderlying` function.

`classUnderlying(quatOnes)`
```ans = 'single' ```

## Input Arguments

collapse all

Size of square quaternion matrix, specified as an integer value.

If `n` is zero or negative, then `quatOnes` is returned as an empty matrix.

Example: `ones(4,'quaternion')` returns a 4-by-4 matrix of quaternions with the real parts set to `1` and the imaginary parts set to `0`.

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

Output size, specified as a row vector of integer values. Each element of `sz` indicates the size of the corresponding dimension in `quatOnes`. If the size of any dimension is `0` or negative, then `quatOnes` is returned as an empty array.

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

Quaternion prototype, specified as a variable.

Example: `ones(2,'like',quat,'quaternion')` returns a 2-by-2 matrix of quaternions with the same underlying class as the prototype quaternion, `quat`.

Data Types: `quaternion`

Size of each dimension, specified as two or more integers. If the size of any dimension is `0` or negative, then `quatOnes` is returned as an empty array.

Example: `ones(2,3,'quaternion')` returns a 2-by-3 matrix of quaternions with the real parts set to `1` and the imaginary parts set to `0`.

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

## Output Arguments

collapse all

Quaternion ones, returned as a scalar, vector, matrix, or multidimensional array of quaternions.

Given a quaternion of the form $Q=a+b\text{i}+c\text{j}+d\text{k}$, a quaternion one is defined as $Q=1+0\text{i}+0\text{j}+0\text{k}$.

Data Types: `quaternion`

## Version History

Introduced in R2021a