MATLAB Examples

# fliplrn, flipudn, and flipdimn

Flip multiple matrices along specified dimensions.

## Syntax

```Af = fliplrn(A)
[Af1,Af2,...,Afn] = fliplrn(A1,A2,...,An)
Af = flipudn(A)
[Af1,Af2,...,Afn] = flipudn(A1,A2,...,An)
Af = fliplrn(A,dim)
[Af1,Af2,...,Afn] = flipdimn(A1,A2,...,An,dim)```

## Description

Af = fliplrn(A) returns A with columns flipped in the left-right direction, that is, about a vertical axis. If A is a row vector, then fliplrn(A) returns a vector of the same length with the order of its elements reversed. If A is a column vector, then fliplrn(A) simply returns A. fliplrn with one input matrix is exactly the same as fliplr.

[Af1,Af2,...,Afn] = fliplrn(A1,A2,...,An) returns multiple matrices flipped about their vertical axes.

Af = flipudn(A) returns A with columns flipped in the up-down direction, that is, about a horizontal axis. If A is a column vector, then fliplrn(A) returns a vector of the same length with the order of its elements reversed. If A is a row vector, then fliplrn(A) simply returns A. flipudn with one input matrix is exactly the same as flipud.

[Af1,Af2,...,Afn] = flipudn(A1,A2,...,An) returns multiple matrices flipped about their horizontal axes.

Af = flipdimn(A,dim) returns A with dimension dim flipped. When the value of dim is 1, the array is flipped row-wise down. When dim is 2, the array is flipped columnwise left to right. flipdimn(A,1) is the same as flipudn(A), and flipdimn(A,2) is the same as fliplr(A). flipdimn with one input matrix is exactly the same as flipdim.

[Af1,Af2,...,Afn] = flipdimn(A1,A2,...,An,dim) returns multiple matrices with dimension dim flipped.

## Example of fliplrn

Fliping four matrices using built-in Matlab commands requires four lines of code. Let's start by making up some data:

```a = 1:10; b = [3 4 5]; c = [7;8;9;10]; d = [1 4; 2 5; 3 6]; ```

Flipping these matrices via fliplr requires

```af = fliplr(a) bf = fliplr(b) cf = fliplr(c) df = fliplr(d) ```
```af = 10 9 8 7 6 5 4 3 2 1 bf = 5 4 3 cf = 7 8 9 10 df = 4 1 5 2 6 3 ```

However, using fliplrn we can do it it one line:

```[af,bf,cf,df] = fliplrn(a,b,c,d) ```
```af = 10 9 8 7 6 5 4 3 2 1 bf = 5 4 3 cf = 7 8 9 10 df = 4 1 5 2 6 3 ```

## Example of flipudn

Using the a, b, c, and d matrices from above, flipudn follows a similar form as fliplrn:

```[af,bf,cf,df] = flipudn(a,b,c,d) ```
```af = 1 2 3 4 5 6 7 8 9 10 bf = 3 4 5 cf = 10 9 8 7 df = 3 6 2 5 1 4 ```

## Example of flimdimn

We can flip a, b, c, and d along dimension 1 like this:

```[af,bf,cf,df] = flipdimn(a,b,c,d,1) ```
```af = 1 2 3 4 5 6 7 8 9 10 bf = 3 4 5 cf = 10 9 8 7 df = 3 6 2 5 1 4 ```

Or we can flip a, b, c, and d along dimension 2 like this:

```[af,bf,cf,df] = flipdimn(a,b,c,d,2) ```
```af = 10 9 8 7 6 5 4 3 2 1 bf = 5 4 3 cf = 7 8 9 10 df = 4 1 5 2 6 3 ```

## Author Info

These scripts were written by Chad A. Greene of the University of Texas Institute for Geophysics (UTIG) on August 6, 2014.