Updated March 6, 2023

## Introduction to Matlab Transpose

Transpose is used in mathematics to interchange the rows and columns of the input matrix. So, if we have a 2 x 3 matrix as our input, the transpose function will give us a 3 x 2 matrix as the output. In Matlab, we use the ‘transpose function’ to compute the transpose of a matrix or a vector. For a vector with ‘n’ elements, the transpose function gives a ‘n x 1’ matrix as output (‘n’ rows and 1 column).

**Syntax of transpose function:**

`T = transpose (M)`

`T = M.’`

**Explanation:**

- T = transpose (M) is used to compute the transpose of the input matrix ‘M’, i.e., it will interchange the rows and columns of the matrix ‘M’.
- T = M.’ is another way of computing the transpose. It will give the same output as the above syntax.

### Examples of Matlab Transpose

Given below are the examples of Matlab Transpose:

#### Example #1

In this example, we will use the transpose function to compute the transpose of a 2 x 2 real matrix.

Below are the steps to be followed:

- Initialize the input matrix.
- Pass this input matrix as an argument to the transpose function.

**Code:**

M = [6 -5; 1 6] [Initializing the 2 x 2 input matrix]

T = transpose (M)

[Using the transpose function to compute the transpose of the input matrix]

**Input:**

**Output:**

**Before transpose:**

**After transpose:**

As we can see in the output, the transpose function has interchanged the rows and columns of our input matrix.

#### Example #2

In this example, we will use the transpose function to compute the transpose of a 3 x 3 real matrix.

Below are the steps to be followed:

- Initialize the input matrix.
- Pass this input matrix as an argument to the transpose function.

**Code:**

M = [2 -1 4; 1 16 2; 0 -4 3] [Initializing the 3 x 3 input matrix]

T = transpose (M)

[Using the transpose function to compute the transpose of the input matrix]

**Input:**

**Output:**

**Before transpose:**

**After transpose:**

As we can see in the output, the transpose function has interchanged the rows and columns of our input matrix.

In the above 2 examples, our input matrix was of real elements.

Next, let us take an example where our input matrix will have complex elements as well.

#### Example #3

In this example, we will use the transpose function to compute the transpose of a 3 x 3 complex matrix.

Below are the steps to be followed:

- Initialize the input matrix with complex elements.
- Pass this input matrix as an argument to the transpose function.

**Code:**

M = [2+3i 1-4i 1; 1+3i 0 3-2i; 0 3 2] [Initializing the 3 x 3 input matrix with complex elements]

T = transpose (M)

[Using the transpose function to compute the transpose of the input matrix]

**Input:**

**Output:**

**Before transpose:**

**After transpose:**

As we can see in the output, the transpose function has interchanged the rows and columns of our input complex matrix.

In the above 3 examples, we have used a square matrix as our input.

Next, we will use a non-square matrix as input to the transpose function.

#### Example #4

In this example, we will use the transpose function to compute the transpose of a 2 x 3 real matrix.

Below are the steps to be followed:

- Initialize the input matrix.
- Pass this input matrix as an argument to the transpose function.

**Code:**

M = [1 6 4; 1 4 -2] [Initializing the 2 x 3 input matrix]

T = transpose (M)

[Using the transpose function to compute the transpose of the input matrix]

**Input:**

**Output:**

**Before transpose:**

**After transpose:**

As we can see in the output, the transpose function has interchanged the rows and columns of our non-square input matrix.

In the above 4 examples, we have used a matrix as our input to the transpose function.

Next, we will use the transpose function to compute the transpose of a vector input.

#### Example #5

In this example, we will use the transpose function to compute the transpose of a vector with 5 elements.

Below are the steps to be followed:

- Initialize the input vector with 5 elements.
- Pass this input vector as an argument to the transpose function.

**Code:**

M = [8 -11 4 5 7] [Initializing the input vector with 5 elements]

T = transpose (M)

[Using the transpose function to compute the transpose of the input vector]
Please note that since our input has 5 columns and 1 row, our output will have 5 rows and 1 column.

**Input:**

**Output:**

**Before transpose:**

**After transpose:**

As we can see in the output, the transpose function has interchanged our input vector rows and columns.

### Conclusion

We use the transpose function to compute the transpose of a matrix, i.e., interchange its rows and columns. Transpose function can be used for both real and complex matrices. For a vector input, the transpose function will convert a number of elements in the vector as a number of rows of the output.

### Recommended Articles

This is a guide to Matlab Transpose. Here we discuss the introduction and examples of Matlab transpose for better understanding. You may also have a look at the following articles to learn more –