lettura simple

Flipping a matrix in Octave

In this lesson I'll explain how to flip a matrix horizontally or vertically on Octave.

What does it mean to flip a matrix? It is a transformation of the matrix that you obtain by "mirroring" the matrix with respect to an axis. The order of the rows or columns is reversed. For example, this matrix is flipped horizontally. The order of the columns is reversed. The first column became the last and vice versa.
flipping horizontally a matrix
This other matrix is upside down vertically. The order of the rows is symmetrically reversed. The first row became the last and vice versa.
filipping vertically a matrix

I'll give you a practical example

Create a 3x3 matrix with three rows and three columns.

>> M=[1 2 3; 4 5 6; 7 8 9]
M =
1 2 3
4 5 6
7 8 9

To flip the matrix horizontally you have to reverse the order of the columns from left to right.

Type fliplr(M)

>> fliplr(M)
ans =
3 2 1
6 5 4
9 8 7

The result is a matrix with the reversed order of the columns. The third column becomes the first and vice versa.

To flip the matrix vertically, you need to reverse the order of the rows from top to bottom.

Type flipud(M)

>> flipud(M)
ans =
7 8 9
4 5 6
1 2 3

The result is a matrix with the reverse order of the rows.

The first line becomes the third and vice versa.




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin