Main Content

compact

Convert quaternion array to N-by-4 matrix

Since R2019b

Description

example

matrix = compact(quat) converts the quaternion array, quat, to an N-by-4 matrix. The columns are made from the four quaternion parts. The ith row of the matrix corresponds to quat(i).

Examples

collapse all

Create a scalar quaternion with random parts. Convert the parts to a 1-by-4 vector using compact.

randomParts = randn(1,4)
randomParts = 1×4

    0.5377    1.8339   -2.2588    0.8622

quat = quaternion(randomParts)
quat = quaternion
     0.53767 +  1.8339i -  2.2588j + 0.86217k

quatParts = compact(quat)
quatParts = 1×4

    0.5377    1.8339   -2.2588    0.8622

Create a 2-by-2 array of quaternions, then convert the representation to a matrix of quaternion parts. The output rows correspond to the linear indices of the quaternion array.

quatArray = [quaternion([1:4;5:8]),quaternion([9:12;13:16])]
quatArray = 2x2 quaternion array
      1 +  2i +  3j +  4k      9 + 10i + 11j + 12k
      5 +  6i +  7j +  8k     13 + 14i + 15j + 16k

quatArrayParts = compact(quatArray)
quatArrayParts = 4×4

     1     2     3     4
     5     6     7     8
     9    10    11    12
    13    14    15    16

Input Arguments

collapse all

Quaternion to convert, specified as a quaternion object or an array of quaternion objects of any dimensionality.

Output Arguments

collapse all

Quaternion in matrix form, returned as an N-by-4 numeric matrix, where N is the number of quaternions given in the input quat.

Data Types: single | double

Extended Capabilities

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

Version History

Introduced in R2019b