fliplr - Flip array left to right - MATLAB (original) (raw)
Syntax
Description
B = fliplr([A](#bt6yqfk-1-A))
returns A
with its columns flipped in the left-right direction (that is, about a vertical axis).
If A
is a row vector, then fliplr(A)
returns a vector of the same length with the order of its elements reversed. If A
is a column vector, then fliplr(A)
simply returns A
. For multidimensional arrays, fliplr
operates on the planes formed by the first and second dimensions.
Examples
Create a row vector.
A = 1×10
1 2 3 4 5 6 7 8 9 10
Use fliplr
to flip the elements of A
in the horizontal direction.
B = 1×10
10 9 8 7 6 5 4 3 2 1
The order of the elements in B
is reversed compared to A
.
Create a 3-by-3 cell array of characters.
A = {'a' 'b' 'c'; 'd' 'e' 'f'; 'g' 'h' 'i'}
A = 3×3 cell {'a'} {'b'} {'c'} {'d'} {'e'} {'f'} {'g'} {'h'} {'i'}
Change the order of the columns in the horizontal direction by using fliplr
.
B = 3×3 cell {'c'} {'b'} {'a'} {'f'} {'e'} {'d'} {'i'} {'h'} {'g'}
The order of the first and third columns of A
is switched in B
, 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
A
is an array of size 2-by-2-by-2.
Flip the elements on each page of A
in the horizontal direction.
B = B(:,:,1) =
2 1
4 3
B(:,:,2) =
6 5
8 7
The result, B
, is the same size as A
, but the horizontal order of the elements is flipped. The operation flips the elements on each page independently.
Input Arguments
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)
is equivalent toflip(A,2)
.- Use the flipud function to flip arrays in the vertical direction (that is, about a horizontal axis).
- The flip function can flip arrays in any direction.
Extended Capabilities
Thefliplr
function fully supports tall arrays. For more information, see Tall Arrays.
Usage notes and limitations:
- Does not support cell arrays.
The fliplr
function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced before R2006a