1 ## Copyright (C) 1993-2012 John W. Eaton
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} rot90 (@var{A})
21 ## @deftypefnx {Function File} {} rot90 (@var{A}, @var{k})
22 ## Return a copy of @var{A} with the elements rotated counterclockwise in
23 ## 90-degree increments. The second argument is optional, and specifies
24 ## how many 90-degree rotations are to be applied (the default value is 1).
25 ## Negative values of @var{k} rotate the matrix in a clockwise direction.
30 ## rot90 ([1, 2; 3, 4], -1)
37 ## rotates the given matrix clockwise by 90 degrees. The following are all
38 ## equivalent statements:
42 ## rot90 ([1, 2; 3, 4], -1)
43 ## rot90 ([1, 2; 3, 4], 3)
44 ## rot90 ([1, 2; 3, 4], 7)
48 ## Note that @code{rot90} only works with 2-D arrays. To rotate N-D arrays
49 ## use @code{rotdim} instead.
50 ## @seealso{rotdim, flipud, fliplr, flipdim}
55 function B = rot90 (A, k = 1)
57 if (nargin < 1 || nargin > 2)
62 error ("rot90: A must be a 2-D array");
63 elseif (! (isscalar (k) && isreal (k) && k == fix (k)))
64 error ("rot90: K must be a single real integer");
74 B = flipud (fliplr (A));
78 error ("rot90: internal error!");
90 %! assert(rot90 (x1), x2);
91 %! assert(rot90 (x1, 2), x3);
92 %! assert(rot90 (x1, 3), x4);
93 %! assert(rot90 (x1, 4), x1);
94 %! assert(rot90 (x1, 5), x2);
95 %! assert(rot90 (x1, -1), x4);
97 %% Test input validation
99 %!error rot90 (1, 2, 3);
100 %!error rot90 (1, ones(2));
101 %!error rot90 (1, 1.5);
102 %!error rot90 (1, 1+i);