1 ## Copyright (C) 2004-2012 David Bateman
2 ## Copyright (C) 2009 VZLU Prague
4 ## This file is part of Octave.
6 ## Octave is free software; you can redistribute it and/or modify it
7 ## under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 3 of the License, or (at
9 ## your option) any later version.
11 ## Octave is distributed in the hope that it will be useful, but
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ## General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with Octave; see the file COPYING. If not, see
18 ## <http://www.gnu.org/licenses/>.
21 ## @deftypefn {Function File} {} flipdim (@var{x})
22 ## @deftypefnx {Function File} {} flipdim (@var{x}, @var{dim})
23 ## Return a copy of @var{x} flipped about the dimension @var{dim}.
24 ## @var{dim} defaults to the first non-singleton dimension.
29 ## flipdim ([1, 2; 3, 4], 2)
34 ## @seealso{fliplr, flipud, rot90, rotdim}
37 ## Author: David Bateman, Jaroslav Hajek
39 function y = flipdim (x, dim)
41 if (nargin != 1 && nargin != 2)
48 ## Find the first non-singleton dimension.
49 (dim = find (sz > 1, 1)) || (dim = 1);
50 elseif (! (isscalar (dim) && isindex (dim)))
51 error ("flipdim: DIM must be a positive integer");
54 idx(1:max(nd, dim)) = {':'};
55 idx{dim} = size (x, dim):-1:1;
61 %!error flipdim (1, 2, 3);
63 %!assert (flipdim ([1,2;3,4]), flipdim ([1,2 ; 3,4], 1));
64 %!assert (flipdim ([1,2;3,4], 2), [2,1;4,3]);
65 %!assert (flipdim ([1,2;3,4], 3), [1,2;3,4]);
67 ## FIXME -- we need tests for multidimensional arrays.