flip

Reverses the order of elements along a dimension.

Category: Language Fundamentals > Matrices and Arrays

Syntax

B = flip(A)

Reverses along the first non-singleton dimension.

B = flip(A, dim)

Reverses along dimension dim.

Description

For a vector, flip reverses it whatever its orientation. For a matrix without dim it flips the rows, like flipud; with dim = 2 it flips the columns, like fliplr. It also reverses text, so flip('abc') is 'cba'.

Input arguments

A
Array of any type, including text and cell arrays.
dim
Dimension to flip: 1 turns rows upside down, 2 mirrors left to right.

Output arguments

B
Array of the same size and class as A.

Example

flip([1 2 3])
flip([1 2; 3 4])
flip([1 2; 3 4], 2)
flip('abc')
Output
ans = 1×3

     3     2     1
ans = 2×2

     3     4
     1     2
ans = 2×2

     2     1
     4     3
ans = 'cba'

See also

fliplr flipud rot90 circshift sort