2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
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 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
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. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
245
|
19 |
3369
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} rot90 (@var{x}, @var{n}) |
|
22 ## Return a copy of @var{x} 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{n} rotate the matrix in a clockwise direction. |
|
26 ## For example, |
|
27 ## |
|
28 ## @example |
|
29 ## @group |
|
30 ## rot90 ([1, 2; 3, 4], -1) |
|
31 ## @result{} 3 1 |
|
32 ## 4 2 |
|
33 ## @end group |
|
34 ## @end example |
|
35 ## |
|
36 ## @noindent |
|
37 ## rotates the given matrix clockwise by 90 degrees. The following are all |
|
38 ## equivalent statements: |
|
39 ## |
|
40 ## @example |
|
41 ## @group |
|
42 ## rot90 ([1, 2; 3, 4], -1) |
|
43 ## @equiv{} |
|
44 ## rot90 ([1, 2; 3, 4], 3) |
|
45 ## @equiv{} |
|
46 ## rot90 ([1, 2; 3, 4], 7) |
|
47 ## @end group |
|
48 ## @end example |
|
49 ## @end deftypefn |
3408
|
50 ## @seealso{flipud and fliplr} |
4
|
51 |
2314
|
52 ## Author: jwe |
|
53 |
2311
|
54 function y = rot90 (x, k) |
4
|
55 |
|
56 if (nargin < 2) |
|
57 k = 1; |
|
58 endif |
|
59 |
|
60 if (imag (k) != 0 || fix (k) != k) |
|
61 error ("rot90: k must be an integer"); |
|
62 endif |
|
63 |
|
64 if (nargin == 1 || nargin == 2) |
|
65 k = rem (k, 4); |
|
66 if (k < 0) |
|
67 k = k + 4; |
|
68 endif |
|
69 if (k == 0) |
|
70 y = x; |
|
71 elseif (k == 1) |
3238
|
72 y = flipud (x.'); |
4
|
73 elseif (k == 2) |
|
74 y = flipud (fliplr (x)); |
|
75 elseif (k == 3) |
3238
|
76 y = (flipud (x)).'; |
4
|
77 else |
|
78 error ("rot90: internal error!"); |
|
79 endif |
|
80 else |
904
|
81 usage ("rot90 (x [, k])"); |
4
|
82 endif |
|
83 |
|
84 endfunction |