Categories
1. Some Basic Tips

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:

Matlab Transpose 1

Output:

Before transpose:

Matlab Transpose 2

After transpose:

Matlab Transpose 3

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:
Matlab Transpose 4

Output:

Before transpose:

Matlab Transpose 5

After transpose:

Matlab Transpose 6

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:

3 x 3 complex matrix

Output:

Before transpose:

Before

After transpose:

After

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:

2 x 3 real matrix

Output:

Before transpose:

Before transpose

After transpose:

Matlab Transpose 12

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:

of a vector with 5 elements

Output:

Before transpose:

Before

After transpose:

Matlab Transpose 15

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

Leave a Reply

Your email address will not be published. Required fields are marked *