Main Content

fliplr

Flip array left to right

Description

example

B = fliplr(A)returnsAwith its columns flipped in the left-right direction (that is, about a vertical axis).

IfAis a row vector, thenfliplr(A)returns a vector of the same length with the order of its elements reversed. IfAis a column vector, thenfliplr(A)simply returnsA. For multidimensional arrays,fliplroperates on the planes formed by the first and second dimensions.

Examples

collapse all

Create a row vector.

A = 1:10
A =1×101 2 3 4 5 6 7 8 9 10

Usefliplrto flip the elements ofAin the horizontal direction.

B = fliplr (A)
B =1×1010 9 8 7 6 5 4 3 2 1

The order of the elements inBis reversed compared toA.

Create a 3-by-3 cell array of characters.

A = {'a''b''c';'d''e''f';'g''h''i'}
A =3x3 cell{'a'} {'b'} {'c'} {'d'} {'e'} {'f'} {'g'} {'h'} {'i'}

Change the order of the columns in the horizontal direction by usingfliplr.

B = fliplr (A)
B =3x3 cell{'c'} {'b'} {'a'} {'f'} {'e'} {'d'} {'i'} {'h'} {'g'}

The order of the first and third columns ofAis switched inB, while the second column remains unchanged.

Create a multidimensional array.

A = cat(3, [1 2; 3 4], [5 6; 7 8])
A = A(:,:,1) = 1 2 3 4 A(:,:,2) = 5 6 7 8

Ais an array of size 2-by-2-by-2.

Flip the elements on each page ofAin the horizontal direction.

B = fliplr (A)
B = B(:,:,1) = 2 1 4 3 B(:,:,2) = 6 5 8 7

The result,B, is the same size asA, but the horizontal order of the elements is flipped. The operation flips the elements on each page independently.

Input Arguments

collapse all

Input array, specified as a vector, matrix, multidimensional array, table, or timetable.

Data Types:double|single|int8|int16|int32|int64|uint8|uint16|uint32|uint64|logical|char|string|struct|cell|table|timetable|categorical|datetime|duration|calendarDuration

Complex Number Support:Yes

Tips

  • fliplr(A)相当于flip(A,2).

  • Use theflipudfunction to flip arrays in the vertical direction (that is, about a horizontal axis).

  • Theflipfunction can flip arrays in any direction.

Extended Capabilities

Version History

Introduced before R2006a

See Also

||