Documentation Center

  • Trials
  • Product Updates

flipud

Flip array up to down

Syntax

Description

example

B = flipud(A) returns A with its rows flipped in the up-down direction (that is, about a horizontal axis).

If A is a column vector, then flipud(A) returns a vector of the same length with the order of its elements reversed. If A is a row vector, then flipud(A) simply returns A. For multidimensional arrays, flipud operates on the planes formed by the first and second dimensions.

Examples

expand all

Flip Column Vector

Create a column vector.

A=(1:10)'
A =

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10

Use flipud to flip the elements of A in the vertical direction.

B = flipud(A)
B =

    10
     9
     8
     7
     6
     5
     4
     3
     2
     1

The order of the elements in B is reversed compared to A.

Flip Cell Array of Strings

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

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

    'a'    'b'    'c'
    'd'    'e'    'f'
    'g'    'h'    'i'

Change the order of the rows in the vertical direction by using flipud.

B = flipud(A)
B = 

    'g'    'h'    'i'
    'd'    'e'    'f'
    'a'    'b'    'c'

The order of the first and third rows of A is switched in B, while the second row remains unchanged.

Flip Multidimensional Array

Create a multidimensional array.

A = cat(3, [1 2; 3 4], [5 6; 7 8])
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 vertical direction.

B = flipud(A)
B(:,:,1) =

     3     4
     1     2


B(:,:,2) =

     7     8
     5     6

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

Input Arguments

expand all

A — Input arrayvector | matrix | array | cell array | categorical array | table

Input array, specified as a vector, matrix, array, cell array, categorical array, or table of any data type.

Complex Number Support: Yes

More About

expand all

Tips

  • flipud(A) is equivalent to flip(A,1).

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

  • The flip function can flip arrays in any direction.

See Also

| |

Was this topic helpful?