Skip to content

MATLAB - Transpose Operator

The transpose is a fundamental matrix operation that swaps a matrix’s rows with its columns. It’s widely used in linear algebra, data analysis, and many scientific computing tasks. This tutorial covers how to perform transposition in MATLAB, highlighting a critical distinction when working with complex numbers.

The transpose of a matrix A is denoted as AT. If A is an m x n matrix, then AT will be an n x m matrix. The element at row i, column j in the original matrix moves to row j, column i in the transposed matrix.

For example, consider the following 3x3 matrix M:

M =
1 2 3
4 5 6
7 8 9

The transpose of matrix M, denoted M_T, would be:

M_T =
1 4 7
2 5 8
3 6 9

An important property is that transposing a matrix twice returns the original matrix: (AT)T = A.

MATLAB provides two main operators for transposition, and it’s crucial to understand their difference:

  • .' (dot-apostrophe): Performs the standard, non-conjugate transpose.
  • ' (apostrophe): Performs the complex conjugate transpose (also known as the Hermitian transpose or adjoint).

For matrices containing only real numbers, both operators (.' and ') produce the same result.

%% Create a real matrix
realMatrix = [1, 2, 3; 4, 5, 6; 7, 8, 9];
%% Using the non-conjugate transpose operator (.')
transpose1 = realMatrix.';
%% Using the conjugate transpose operator (')
transpose2 = realMatrix';
% Display the results
disp('Original Matrix:');
disp(realMatrix);
disp('Transpose using .'':');
disp(transpose1);
disp('Transpose using '':'');
disp(transpose2);

Executing this code will show that transpose1 and transpose2 are identical:

Original Matrix:
1 2 3
4 5 6
7 8 9
Transpose using .':
1 4 7
2 5 8
3 6 9
Transpose using ':
1 4 7
2 5 8
3 6 9

Transposing Complex Matrices: The Critical Difference

Section titled “Transposing Complex Matrices: The Critical Difference”

The difference between the two operators becomes apparent when working with complex numbers. The complex conjugate of a number a + bi is a - bi.

  • A.' (Non-conjugate transpose) simply swaps rows and columns.
  • A' (Complex conjugate transpose) swaps rows and columns AND takes the complex conjugate of each element.
%% Create a complex matrix
complexMatrix = [1+2i, 3-4i; 5, 6+7i];
%% Perform non-conjugate transpose
nonConjugateT = complexMatrix.';
%% Perform complex conjugate transpose
conjugateT = complexMatrix';
% Display the results
disp('Original Complex Matrix:');
disp(complexMatrix);
disp('Non-Conjugate Transpose (. ''):');
disp(nonConjugateT);
disp('Complex Conjugate Transpose (''):');
disp(conjugateT);

The output clearly shows the difference:

Original Complex Matrix:
1.0000 + 2.0000i 3.0000 - 4.0000i
5.0000 + 0.0000i 6.0000 + 7.0000i
Non-Conjugate Transpose (. '):
1.0000 + 2.0000i 5.0000 + 0.0000i
3.0000 - 4.0000i 6.0000 + 7.0000i
Complex Conjugate Transpose ('):
1.0000 - 2.0000i 5.0000 + 0.0000i
3.0000 + 4.0000i 6.0000 - 7.0000i

Pro Tip: Unless you specifically require the complex conjugate transpose for a mathematical algorithm (e.g., in linear algebra for Hermitian matrices), it is a modern best practice to default to the dot-transpose operator (.).

This prevents subtle bugs if your code unexpectedly receives complex data, for example, from a Fast Fourier Transform (FFT).

MATLAB also provides functions that mirror the behavior of the operators. While operators are generally more idiomatic and common in MATLAB code, these functions can be useful when passing an operation as a function handle.

  • transpose(A): Equivalent to A.' (non-conjugate).
  • ctranspose(A): Equivalent to A' (complex conjugate).
%% Using the transpose() function
funcTranspose = transpose(complexMatrix);
disp('Result from transpose() function:');
disp(funcTranspose);
%% Using the ctranspose() function
funcCTranspose = ctranspose(complexMatrix);
disp('Result from ctranspose() function:');
disp(funcCTranspose);

The output of this code will match the respective operator-based results shown previously.