Tutorial

How to Transpose a 2D Matrix in MATLAB

The transpose operation of a 2D matrix causes that rows become columns and columns become rows.

Preparation

Create two matrices using the following code:

A = [1:3;4:6];
B = [1+1i, 1+2i, 1+3i];

Transpose operation

The transpose operation of a 2D matrix interchanges the row and column index of each element, therefore rows become columns and columns become rows.

MATLAB supports two types of transpose operations: complex conjugate transpose, and nonconjugate transpose. The difference is that the complex conjugate transpose negates the imaginary part of complex numbers in the input, while the other operation leaves them intact.

Syntax

B = A' stores in B the complex conjugate transpose of A. B = A.' stores in B the nonconjugate transpose of A.

Both operations only support 2D inputs.
% Complex conjugate transpose of A
resultExample1 = A';
% Nonconjugate transpose of A
resultExample2 = A.';
% Complex conjugate transpose of B
resultExample3 = B';
% Nonconjugate transpose of B
resultExample4 = B.';

Further reading

I recommend the following books to learn more on matrix manipulation in MATLAB.

  1. MATLAB: A Practical Introduction to Programming and Problem Solving (4th Edition)

    This book was the winner of a 2017 Textbook Excellence Award. The second chapter explains how to perform a wide list of operations on matrices, including the transpose operation.

  2. MATLAB for Engineers (5th Edition)

    This excellent book is especially oriented to engineers and scientists who want to learn MATLAB programming. Matrix manipulation is explained in the fourth chapter.

I also recommend the following pages in the MATLAB help documentation, and the other tutorials in this series.

doc ctranspose;
doc transpose;

Source code

I hope you have learned how to transpose a 2D matrix in MATLAB. The source code developed in this tutorial is available at this page.

Share

Your friends may need this knowledge to complete a task. Share this tutorial.