1########################################################################
2##
3## Copyright (C) 1993-2021 The Octave Project Developers
4##
5## See the file COPYRIGHT.md in the top-level directory of this
6## distribution or <https://octave.org/copyright/>.
7##
8## This file is part of Octave.
9##
10## Octave is free software: you can redistribute it and/or modify it
11## under the terms of the GNU General Public License as published by
12## the Free Software Foundation, either version 3 of the License, or
13## (at your option) any later version.
14##
15## Octave is distributed in the hope that it will be useful, but
16## WITHOUT ANY WARRANTY; without even the implied warranty of
17## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18## GNU General Public License for more details.
19##
20## You should have received a copy of the GNU General Public License
21## along with Octave; see the file COPYING.  If not, see
22## <https://www.gnu.org/licenses/>.
23##
24########################################################################
25
26## -*- texinfo -*-
27## @deftypefn {} {} flipud (@var{x})
28## Flip array upside down.
29##
30## Return a copy of @var{x} with the order of the rows reversed.  In other
31## words, @var{x} is flipped upside-down about a horizontal axis.  For example:
32##
33## @example
34## @group
35## flipud ([1, 2; 3, 4])
36##      @result{}  3  4
37##          1  2
38## @end group
39## @end example
40##
41## @seealso{fliplr, flip, rot90, rotdim}
42## @end deftypefn
43
44function y = flipud (x)
45
46  if (nargin != 1)
47    print_usage ();
48  endif
49  y = flip (x, 1);
50
51endfunction
52
53
54%!assert (flipud ([1, 2; 3, 4]), [3, 4; 1, 2])
55%!assert (flipud ([1, 2; 3, 4; 5, 6]), [5, 6; 3, 4; 1, 2])
56%!assert (flipud ([1, 2, 3; 4, 5, 6]), [4, 5, 6; 1, 2, 3])
57%!assert (flipud ([1 2 3]), [1 2 3])
58
59## Test NDArrays
60%!test
61%! a(:,:,1) = [ 1  2  3;  4  5  6];
62%! a(:,:,2) = [ 7  8  9; 10 11 12];
63%! b(:,:,1) = [ 4  5  6;  1  2  3];
64%! b(:,:,2) = [10 11 12;  7  8  9];
65%! assert (flipud (a), b);
66
67## Test NDArray with singleton dimensions
68%!test
69%! a(:,:,:,1) = [ 1  2  3;  4  5  6];
70%! a(:,:,:,2) = [ 7  8  9; 10 11 12];
71%! b(:,:,:,1) = [ 4  5  6;  1  2  3];
72%! b(:,:,:,2) = [10 11 12;  7  8  9];
73%! assert (flipud (a), b);
74
75## Test for 1 row, i.e., returns the same
76%!test
77%! a(1,:,:,1) = [ 1  2  3  4];
78%! a(1,:,:,2) = [ 5  6  7  8];
79%! assert (flipud (a), a);
80
81%!error flipud ()
82%!error flipud (1, 2)
83