Mercurial > hg > octave-nkf
annotate scripts/general/rotdim.m @ 11472:1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 09 Jan 2011 21:33:04 -0800 |
parents | 6622772a0add |
children | fd0a3ac60b0e |
rev | line source |
---|---|
9245 | 1 ## Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 David Bateman |
5012 | 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5012 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5012 | 18 |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {} rotdim (@var{x}, @var{n}, @var{plane}) | |
21 ## Return a copy of @var{x} with the elements rotated counterclockwise in | |
22 ## 90-degree increments. The second argument is optional, and specifies | |
23 ## how many 90-degree rotations are to be applied (the default value is 1). | |
24 ## The third argument is also optional and defines the plane of the | |
9041
853f96e8008f
Cleanup documentation file matrix.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
25 ## rotation. As such @var{plane} is a two element vector containing two |
853f96e8008f
Cleanup documentation file matrix.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
26 ## different valid dimensions of the matrix. If @var{plane} is not given |
5012 | 27 ## Then the first two non-singleton dimensions are used. |
28 ## | |
29 ## Negative values of @var{n} rotate the matrix in a clockwise direction. | |
30 ## For example, | |
31 ## | |
32 ## @example | |
33 ## @group | |
34 ## rotdim ([1, 2; 3, 4], -1, [1, 2]) | |
35 ## @result{} 3 1 | |
36 ## 4 2 | |
37 ## @end group | |
38 ## @end example | |
39 ## | |
40 ## @noindent | |
41 ## rotates the given matrix clockwise by 90 degrees. The following are all | |
42 ## equivalent statements: | |
43 ## | |
44 ## @example | |
45 ## @group | |
5487 | 46 ## rotdim ([1, 2; 3, 4], -1, [1, 2]) |
47 ## rotdim ([1, 2; 3, 4], 3, [1, 2]) | |
48 ## rotdim ([1, 2; 3, 4], 7, [1, 2]) | |
5012 | 49 ## @end group |
50 ## @end example | |
5642 | 51 ## @seealso{rot90, flipud, fliplr, flipdim} |
5012 | 52 ## @end deftypefn |
53 | |
10689
6622772a0add
rotdim.m: Modify function to use same variable names as documentation
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
54 function y = rotdim (x, n, plane) |
5012 | 55 |
56 if (nargin < 1 || nargin > 3) | |
6046 | 57 print_usage (); |
5012 | 58 endif |
59 | |
10689
6622772a0add
rotdim.m: Modify function to use same variable names as documentation
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
60 if (nargin > 1 && ! isempty(n)) |
6622772a0add
rotdim.m: Modify function to use same variable names as documentation
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
61 if (!isscalar (n) || !isreal(n) || fix (n) != n) |
6622772a0add
rotdim.m: Modify function to use same variable names as documentation
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
62 error ("rotdim: N must be a scalar integer"); |
5012 | 63 endif |
64 else | |
10689
6622772a0add
rotdim.m: Modify function to use same variable names as documentation
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
65 n = 1; |
5012 | 66 endif |
67 | |
68 nd = ndims (x); | |
69 sz = size (x); | |
70 if (nargin < 3) | |
71 ## Find the first two non-singleton dimension. | |
72 plane = []; | |
73 dim = 0; | |
74 while (dim < nd) | |
75 dim = dim + 1; | |
76 if (sz (dim) != 1) | |
10549 | 77 plane = [plane, dim]; |
78 if (length (plane) == 2) | |
79 break; | |
80 endif | |
5012 | 81 endif |
82 endwhile | |
83 if (length (plane) < 1) | |
84 plane = [1, 2]; | |
85 elseif (length (plane) < 2) | |
86 plane = [1, plane]; | |
87 endif | |
88 else | |
89 if (! (isvector (plane) && length (plane) == 2 | |
10549 | 90 && all (plane == round (plane)) && all (plane > 0) |
91 && all (plane < (nd + 1)) && plane(1) != plane(2))) | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10689
diff
changeset
|
92 error ("rotdim: PLANE must be a 2 element integer vector defining a valid PLANE"); |
5012 | 93 endif |
94 endif | |
95 | |
10689
6622772a0add
rotdim.m: Modify function to use same variable names as documentation
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
96 n = rem (n, 4); |
6622772a0add
rotdim.m: Modify function to use same variable names as documentation
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
97 if (n < 0) |
6622772a0add
rotdim.m: Modify function to use same variable names as documentation
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
98 n = n + 4; |
5012 | 99 endif |
10689
6622772a0add
rotdim.m: Modify function to use same variable names as documentation
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
100 if (n == 0) |
5012 | 101 y = x; |
10689
6622772a0add
rotdim.m: Modify function to use same variable names as documentation
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
102 elseif (n == 2) |
5018 | 103 y = flipdim (flipdim (x, plane(1)), plane(2)); |
10689
6622772a0add
rotdim.m: Modify function to use same variable names as documentation
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
104 elseif (n == 1 || n == 3) |
5012 | 105 perm = 1:nd; |
106 perm(plane(1)) = plane(2); | |
107 perm(plane(2)) = plane(1); | |
108 y = permute (x, perm); | |
10689
6622772a0add
rotdim.m: Modify function to use same variable names as documentation
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
109 if (n == 1) |
5012 | 110 y = flipdim (y, min (plane)); |
111 else | |
112 y = flipdim (y, max (plane)); | |
113 endif | |
114 else | |
115 error ("rotdim: internal error!"); | |
116 endif | |
117 | |
118 endfunction |