Swapping quaternion x and z values I have two coordinate frames of reference. The second one is different from the first one in that the $x$ and $z$ axes are interchanged.
If I get a quaternion representing a rotation in the first frame and I want to find the equivalent in the second frame, can I simply swap the $x$ and $z$ quaternion values?
That is, $q_1= [q_1.w, q_1.x, q_1.y, q_1.z]$ in the first frame becomes 
$q_2= [q_2.w, q_2.z, q_2.y, q_2.x]$ in the second frame
 A: Generally, when two axes are exchanged, but all orientations stay the same otherwise, then the coordinate system handedness changes and $q_2.w$ must be assigned the value of $-q_1.w$ in order to maintain rotation correctness (or, alternatively, the sign of $q.w$ may remain the same, but the signs of all other components must be flipped).
So, based on the information you provided, I'd assume $q_2=[-q_1.w, q_1.x, q_1.z, q_1.y]$
A: $
\newcommand\R{\mathbb R}
$
Yes, but you also have to take the conjugate.
Without going into too much detail, we can think of quaternions as elements of the 3D real Euclidean Clifford algebra, which is a way of defining a product on vectors in $\R^3$ (though the product of two vectors need not be a vector). This product is not necessarily commutative, but it is associative. It's defining property is that vectors square to scalars. There is an element $I$ of the Clifford algebra, called a (left-handed, unit) pseudoscalar, which commutes with the whole algebra and is such that if $v \in \R^3$ then $vI$ is the corresponding (imaginary) quaternion.
Swapping the $x$- and $z$-axes results in a reflection. Where the Clifford algebra helps us is that for any $v, x \in \R^3$ (with $v^2 = 1$ for simplicity), the quantity $-vxv$ is exactly the reflection of $x$ through the plane orthogonal to $v$ (and it follows from this that a unit quaternion $q$ performs a rotation via $qx\bar q$). So let $x$ be in your first coordinate system and $x'$ be the corresponding vector in your second system so that
$$
  x = -vx'v,\quad v = \frac1{\sqrt2}(e_z - e_x),
$$
where $e_x, e_z$ are the positive unit vectors along the $x$ and $z$ axes, respectively. This $v$ is a unit vector so $v^2 = 1$. Then a unit quaternion $q$ acts on $x$ by
$$
  x \mapsto qx\bar q,
$$
but this means
$$
  -vx'v \mapsto -qvx'v\bar q
  \implies
  x' \mapsto vqvx'v\bar qv,
$$
and I will state that it is a fact that $v\bar qv = \overline{vqv}$. Hence $q$ maps from system 1 to system 2 via
$$
  q \mapsto q' = vqv.
$$
Every quaternion $q$ is of the form $q = q_R + q_II$ where $q_R \in \R$ and $q_I \in \R^3$, so
$$
  q' = vqv = q_Rv^2 + vq_IIv = q_R - (-vq_Iv)I,
$$
the last equality following since $v^2 = 1$ and $I$ commutes with the whole algebra. To get $q'$ then, we see that we need to

*

*Swap the $x$ and $z$ components of the imaginary part of $q$ (equivalently, the $i$ and $k$ components). This is the $-vq_Iv$ part above.

*Take the conjugate. This is the minus sign between $q_R$ and $(-vq_Iv)I$.

