take transpose of a matrix in matlab

To take the transpose of a matrix A, you can use the ' (conjugate transpose) or .' (transpose) operators.

Here's an example code:

main.m
A = [1 2 3; 4 5 6; 7 8 9]; % example matrix
B = A.'; % taking transpose using .' operator
C = A'; % taking transpose using ' operator

disp(B) % displaying transpose
disp(C)
174 chars
7 lines

This will output:

main.m
B =

     1     4     7
     2     5     8
     3     6     9

C =

     1     4     7
     2     5     8
     3     6     9

126 chars
13 lines

Here, both B and C are the transpose of matrix A. The difference between the two operators is that ' also performs complex conjugate of the matrix elements, while .' only takes the transpose.

related categories

gistlibby LogSnag