Qu

flipud

Builtin index · Core maths

result = flip(A, dim=1)

Input: A, dim · Output: result

What it is

Reverses row order (flipud, dim=1) or column order (fliplr/mirror, dim=2) of A, a Str, Vec, Mat, or Image. On a Str every spelling reverses the character order; on a plain Vec (which has no row/column orientation) both directions just reverse element order. dim (only meaningful for flip) is an optional keyword-or-positional scalar, 1 or 2, defaulting to 1.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = flip(A, dim=1)
A Str, Vec, Mat, or ImageReverses row order (flipud, dim=1) or column order (fliplr/mirror, dim=2) of A, a Str, Vec, Mat, or Image.
dim scalar (default 1)dim (only meaningful for flip) is an optional keyword-or-positional scalar, 1 or 2, defaulting to 1.
result —
Returns the same type and shape as A.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

v = [1, 2, 3, 4]
print("flip(v) = {flip(v)}")            # [4, 3, 2, 1]


A = [1, 2; 3, 4]
print("fliplr(A) = {fliplr(A)}")        # reverses column order: [2, 1; 4, 3]

print("flipud(A) = {flipud(A)}")        # reverses row order:    [3, 4; 1, 2]

print("rot90(A) = {rot90(A)}")          # 90 deg counterclockwise: [2, 4; 1, 3]

print("rot90(A, -1) = {rot90(A, -1)}")  # negative k rotates clockwise instead

output
flip(v) = [4, 3, 2, 1]
fliplr(A) = [2, 1; 4, 3]
flipud(A) = [3, 4; 1, 2]
rot90(A) = [2, 4; 1, 3]
rot90(A, -1) = [3, 1; 4, 2]

from fundamentals

How it works

flipud(A)/fliplr(A) — reverse row order / column order. On a plain Vec (no row/column orientation of its own), both just reverse the element order — mirror is an alias for fliplr, the more common colloquial name for the same operation. flip(A, [dim=1]) picks between the two by MATLAB's own dimension numbering (dim=1 rows, dim=2 columns); on a Vec, dim is accepted but has no effect since there's only one axis to reverse either way.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.

See also

fliplr, mirror, flip — documented in the same entry.