Skip to main content
Logo image

Section 2.3 Transposing Arrays

Sometimes it is useful to exchange rows and columns of a matrix. This operation is called the “transpose”. More specifically, transposing a matrix \(A\) basically flips it over its diagonal. The outcome is another matrix, often denoted by \(A^T\) (among other notations). Expressed mathematically, here is what happens:
The transpose of a matrix A is just:
\begin{equation*} B = A^T, \text{ where } \,b_{ij} = a_{ji} \end{equation*}
So if \(A\) is a matrix with 7 rows and 4 columns, then \(B = A^T\) is a matrix with 4 rows and 7 columns. The first row of \(B\) simply consists of the elements of the first column of \(A\text{,}\) the second row of \(B\) is the second column of \(A\text{,}\) etc.
In particular, the transpose of a 1xm row vector is thus an mx1 column vector.
If you know matrix multiplication then having the transpose operator allows you to find the inner product of two row vectors x and y via:
\begin{equation*} x \times y^T \end{equation*}
that is, a 1xm times an mx1. The result is a 1x1 and thus a scalar (number).
The transpose operator in MATLAB is the apostrophe '. Here are some examples:
>> rv = [5 20 45]
rv =
    5 20 45
>> cv = rv'
cv =
    5
    20
    45
>> rv*cv
ans =
    2450
>> a = [5 20 45 30; 20 10 1 2]
a =
     5 20 45 30
    20 10  1  2
>> b = a'
b =
     5 20
    20 10
    45  1
    30  2