# dcm2quat

Convert direction cosine matrix to quaternion

## Syntax

``q = dcm2quat(dcm)``
``q = dcm2quat(dcm,action)``
``q = dcm2quat(dcm,action,tolerance)``

## Description

example

````q = dcm2quat(dcm)` calculates the quaternion `q` for a given direction cosine matrix, `dcm`.`q = dcm2quat(dcm,action)` performs an action, `action`, if the direction cosine matrix is invalid, that is not orthogonal.`q = dcm2quat(dcm,action,tolerance)` uses a tolerance level, `tolerance`, to evaluate if the direction cosine matrix `dcm` is within tolerance. ```

## Examples

collapse all

Determine the quaternion from a direction cosine matrix.

```dcm = [0 1 0; 1 0 0; 0 0 -1]; q = dcm2quat(dcm)```
```q = 1×4 0 0.7071 0.7071 0 ```

This example shows how to determine the quaternions from multiple direction cosine matrices.

```dcm = [ 0 1 0; 1 0 0; 0 0 -1]; dcm(:,:,2) = [ 0.4330 0.2500 -0.8660; ... 0.1768 0.9186 0.3536; ... 0.8839 -0.3062 0.3536]; q = dcm2quat(dcm)```
```q = 2×4 0 0.7071 0.7071 0 0.8224 0.2006 0.5320 0.0223 ```

Determine the quaternion from direction cosine matrix `dcm` within tolerance.

```dcm = [0 1 0; 1 0 0; 0 0 -1]; q = dcm2quat(dcm, 'Warning', 0.01)```
```q = 1×4 0 0.7071 0.7071 0 ```

## Input Arguments

collapse all

Direction cosine matrix, specified as a 3-by-3-by-M matrix.

Data Types: `double`

Function behavior when direction cosine matrix is invalid, that is, not orthogonal.

• `'Warning'` — Displays warning and indicates that the direction cosine matrix is invalid.

• `'Error'` — Displays error and indicates that the direction cosine matrix is invalid.

• `'None'` — Does not display warning or error.

Data Types: `char` | `string`

Tolerance of direction cosine matrix validity, specified as a scalar. The function considers the direction cosine matrix valid if these conditions are true:

• The transpose of the direction cosine matrix times itself equals `1` within the specified tolerance (```transpose(dcm)*dcm == 1±tolerance```).

• The determinant of the direction cosine matrix equals `1` within the specified tolerance (`det(dcm) == 1±tolerance`).

Data Types: `double`

## Output Arguments

collapse all

Quaternion, returned in an m-by-4 matrix. `q` has a scalar number as the first column.

## Version History

Introduced in R2006b