Main Content

compact

Convert quaternion array toN-by-4 matrix

Description

example

matrix= compact(quat)converts the quaternion array,quat, to anN-by-4 matrix. The columns are made from the four quaternion parts. Theithrow of the matrix corresponds toquat(i).

Examples

collapse all

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

randomParts = randn(1,4)
randomParts =1×40.5377 1.8339 -2.2588 0.8622
quat = quaternion(randomParts)
quat =quaternion0.53767 + 1.8339i - 2.2588j + 0.86217k
quatParts = compact(quat)
quatParts =1×40.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 array1 + 2i + 3j + 4k 9 + 10i + 11j + 12k 5 + 6i + 7j + 8k 13 + 14i + 15j + 16k
quatArrayParts = compact(quatArray)
quatArrayParts =4×41 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Input Arguments

collapse all

Quaternion to convert, specified as scalar, vector, matrix, or multidimensional array of quaternions.

Data Types:quaternion

Output Arguments

collapse all

Quaternion in matrix form, returned as anN-by-4 matrix, whereN=numel(quat).

Data Types:single|double

Extended Capabilities

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

版本历史

Introduced in R2018b