MATLAB is a tool for performing mathematical operations and data analysis. One common operation that can be performed in MATLAB is taking the transpose of a matrix. This article covers ways of getting Matrix transpose in MATLAB programming.
What is the Transpose of a Matrix
Transpose is defined as interchanging rows with columns or flipping the matrix over its diagonal. In other words, the rows become columns and the columns become rows.
Creating a Matrix in MATLAB
To create a matrix in MATLAB, we can use square brackets to enclose the elements of the matrix. Below is a 2×2 matrix with the elements 1, 2, 3, and 4:
How to Take a Transpose of Matrix in MATLAB
In MATLAB we can obtain matrix transpose using:
Using the Apostrophe Operator
The apostrophe operator (‘) can be used to take the transpose of a matrix. If we want to take the transpose of the above matrix A, the following syntax will be followed:
Using the Transpose Function
In MATLAB we have a transpose function that gives us matrix transpose. We can use the transpose function as follows:
Transpose of a Matrix With Real Numbers
To find the transpose of a matrix with real numbers, each element of the matrix is swapped across the main diagonal. The output matrix will be displayed having both its rows and columns interchanged. Here’s an example in MATLAB:
A = [1, 2, 3; 4, 5, 6; 7, 8, 9];
% Transpose the matrix
A_transpose = A';
% Display the original and transposed matrices
disp("Original Matrix:")
disp(A)
disp("Transposed Matrix:")
disp(A_transpose)
Output
Transpose of a Matrix With Complex Numbers
The transpose of a complex matrix involves finding the complex conjugate of each element and then swapping the rows and columns. In MATLAB, the complex conjugate is obtained using the conj() function. Here’s an example:
B = [1+2i, 3-4i; 5+6i, 7-8i];
% Transpose the matrix
B_transpose = B';
% Display the original and transposed matrices
disp("Original Matrix:")
disp(B)
disp("Transposed Matrix:")
disp(B_transpose)
Output
In the complex matrix example, you can see that the transpose not only swaps the rows and columns but also takes the complex conjugate of each element.
Conclusion
Taking the transpose of a matrix in MATLAB means swapping the rows with columns. MATLAB has a separate transpose() function for this. However, we can also obtain matrix transpose using the apostrophe (‘) sign. Further when we calculate the transpose of complex matrices not only its rows and columns are interchanged, but its conjugate is also taken. Read more on the transpose of a matrix in MATLAB in this article.