1014
|
1 # Copyright (C) 1993, 1994, 1995 John W. Eaton |
245
|
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 the |
|
7 # Free Software Foundation; either version 2, or (at your option) any |
|
8 # later version. |
|
9 # |
|
10 # Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # 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 |
1315
|
17 # Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
245
|
18 |
4
|
19 function y = rot90 (x, k) |
|
20 |
|
21 # usage: rot90 (x, k) |
|
22 # |
|
23 # Rotate the matrix x counterclockwise k*90 degrees. |
|
24 # |
|
25 # If the second argument is omitted, k is taken to be 1. |
|
26 # |
|
27 # See also: flipud, fliplr |
|
28 |
|
29 if (nargin < 2) |
|
30 k = 1; |
|
31 endif |
|
32 |
|
33 if (imag (k) != 0 || fix (k) != k) |
|
34 error ("rot90: k must be an integer"); |
|
35 endif |
|
36 |
|
37 if (nargin == 1 || nargin == 2) |
|
38 k = rem (k, 4); |
|
39 if (k < 0) |
|
40 k = k + 4; |
|
41 endif |
|
42 if (k == 0) |
|
43 y = x; |
|
44 elseif (k == 1) |
|
45 y = flipud (x'); |
|
46 elseif (k == 2) |
|
47 y = flipud (fliplr (x)); |
|
48 elseif (k == 3) |
|
49 y = (flipud (x))'; |
|
50 else |
|
51 error ("rot90: internal error!"); |
|
52 endif |
|
53 else |
904
|
54 usage ("rot90 (x [, k])"); |
4
|
55 endif |
|
56 |
|
57 endfunction |