Scalar component of a quaternion
r = s(q), r = scalar(q)
These two functions extract the scalar component of a quaternion. The result is a real (or a complex value if the quaternion has complex components).
The two functions differ in their behaviour when given a pure quaternion (that is a quaternion with no scalar part). The function s raises an error in this circumstance, whereas scalar returns a zero array of the same size as the pure quaternion, with the same class as the components of the quaternion. For example if the pure quaternion has components of class uint8 the array of zeros returned will also be of class uint8.
>> q = eyeq(2) q = 2x2 quaternion array >> s(q) ans = 1 0 0 1 >> scalar(qi) ans = 0