MATLAB Language Common mistakes and errors The transpose operators


  • .' is the correct way to transpose a vector or matrix in MATLAB.
  • ' is the correct way to take the complex conjugate transpose (a.k.a. Hermitian conjugate) of a vector or matrix in MATLAB.

Note that for the transpose .', there is a period in front of the apostrophe. This is in keeping with the syntax for the other element-wise operations in MATLAB: * multiplies matrices, .* multiplies elements of matrices together. The two commands are very similar, but conceptually very distinct. Like other MATLAB commands, these operators are "syntactical sugar" that gets turned into a "proper" function call at runtime. Just as == becomes an evaluation of the eq function, think of .' as the shorthand for transpose. If you would only write ' (without the point), you are in fact using the ctranspose command instead, which calculates the complex conjugate transpose, which is also known as the Hermitian conjugate, often used in physics. As long as the transposed vector or matrix is real-valued, the two operators produce the same result. But as soon as we deal with complex numbers, we will inevitably run into problems if we do not use the "correct" shorthand. What "correct" is depends on your application.

Consider the following example of a matrix C containing complex numbers:

>> C = [1i, 2; 3*1i, 4]
C =
   0.0000 + 1.0000i   2.0000 + 0.0000i
   0.0000 + 3.0000i   4.0000 + 0.0000i

Let's take the transpose using the shorthand .' (with the period). The output is as expected, the transposed form of C.

>> C.'
ans =
   0.0000 + 1.0000i   0.0000 + 3.0000i
   2.0000 + 0.0000i   4.0000 + 0.0000i

Now, let's use ' (without the period). We see, that in addition to the transposition, the complex values have been transformed to their complex conjugates as well.

>> C'
ans =
   0.0000 - 1.0000i   0.0000 - 3.0000i
   2.0000 + 0.0000i   4.0000 + 0.0000i

To sum up, if you intend to calculate the Hermitian conjugate, the complex conjugate transpose, then use ' (without the period). If you just want to calculate the transpose without complex-conjugating the values, use .' (with the period).