The function `flip` reverses the order of elements in a matrix.

## Preparation

Create a matrix using the following code:

``A = reshape(1:12,2,3,2);``

## Syntax

`B = flip(A,dim)` reverses the order of the elements in `A` along the `dim` dimension, and stores the result in `B`. If `dim` equals 1, `flip` reverses the order of the rows in each plane. If `dim` equals 2, `flip` reverses the order of columns. If `dim` equals 3, `flip` reverses the order of planes, and so on.

Multidimensional matrix: Matrix with more than two dimensions.
``````% Rows of A in reverse order
resultExample1 = flip(A,1);``````
``````% Columns of A in reverse order
resultExample2 = flip(A,2);``````
``````% Planes of A in reverse order
resultExample3 = flip(A,3);``````

I recommend the following books to learn more on matrix manipulation in MATLAB.

1. This book was the winner of a Textbook Excellence Award. The second chapter explains how to perform a wide list of operations on matrices.

2. MATLAB for Engineers (5th Edition)

This excellent book is especially oriented to engineers and scientists who want to learn MATLAB programming. Matrix manipulation is explained in the fourth chapter.

I also recommend the following pages in the MATLAB help documentation, and the other tutorials in this series.

## Source code

I hope you have learned how to reverse a multidimensional matrix in MATLAB. The source code developed in this tutorial is available at this page.