This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

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.


Class of parts within quaternion


underlyingClass = classUnderlying(quat)



underlyingClass = classUnderlying(quat) returns the name of the class of the parts of the quaternion quat.


collapse all

A quaternion is a four-part hyper-complex number used in three-dimensional representations. The four parts of the quaternion are of data type single or double.

Create two quaternions, one with an underlying data type of single, and one with an underlying data type of double. Verify the underlying data types by calling classUnderlying on the quaternions.

qSingle = quaternion(single([1,2,3,4]))
qSingle = quaternion
     1 + 2i + 3j + 4k

ans = 
qDouble = quaternion([1,2,3,4])
qDouble = quaternion
     1 + 2i + 3j + 4k

ans = 

You can separate quaternions into their parts using the parts function. Verify the parts of each quaternion are the correct data type. Recall that double is the default MATLAB® type.

[aS,bS,cS,dS] = parts(qSingle)
aS = single
bS = single
cS = single
dS = single
[aD,bD,cD,dD] = parts(qDouble)
aD = 1
bD = 2
cD = 3
dD = 4

Quaternions follow the same implicit casting rules as other data types in MATLAB. That is, a quaternion with underlying data type single that is combined with a quaternion with underlying data type double results in a quaternion with underlying data type single. Multiply qDouble and qSingle and verify the resulting underlying data type is single.

q = qDouble*qSingle;
ans = 

Input Arguments

collapse all

Quaternion to investigate, specified as a quaternion or array of quaternions.

Data Types: quaternion

Output Arguments

collapse all

Underlying class of quaternion, returned as the character vector 'single' or 'double'.

Data Types: char

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced in R2018a