Mercurial > hg > octave-nkf
annotate scripts/general/rot90.m @ 12639:4d777e05d47c stable
doc: Review and update documentation for "Matrix Manipulation" chapter.
* matrix.txi, arrayfun.m, blkdiag.m, fliplr.m, flipud.m, logspace.m,
postpad.m, prepad.m, randi.m, repmat.m, rot90.m, rotdim.m, shiftdim.m,
sortrows.m, vech.m, xor.m, hadamard.m, hankel.m, hilb.m, invhilb.m, magic.m,
pascal.m, rosser.m, sylvester_matrix.m, toeplitz.m, vander.m, wilkinson.m,
bsxfun.cc, find.cc, lookup.cc, rand.cc, tril.cc, data.cc, arrayfun.m,
blkdiag.m, fliplr.m, flipud.m, logspace.m, postpad.m, prepad.m, randi.m,
repmat.m, rot90.m, rotdim.m, shiftdim.m, sortrows.m, vech.m, xor.m, hadamard.m,
hankel.m, hilb.m, invhilb.m, magic.m, pascal.m, rosser.m, sylvester_matrix.m,
toeplitz.m, vander.m, wilkinson.m, bsxfun.cc (bsxfun), find.cc (find),
lookup.cc (lookup), rand.cc (rand, randn, rande, randg, randp),
tril.cc (triu), data.cc (all, any, horzcat, vertcat, cat, permute, ipermute,
ones, zeros, eye, linspace, resize, reshape, issorted, diff):
Improve docstrings
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 01 May 2011 08:55:15 -0700 |
parents | c792872f8942 |
children | a9d292ce5489 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1993-2011 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
2313 | 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/>. | |
245 | 18 |
3369 | 19 ## -*- texinfo -*- |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
20 ## @deftypefn {Function File} {} rot90 (@var{A}) |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
21 ## @deftypefnx {Function File} {} rot90 (@var{A}, @var{k}) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
22 ## Return a copy of @var{A} with the elements rotated counterclockwise in |
3369 | 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). | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
25 ## Negative values of @var{k} rotate the matrix in a clockwise direction. |
3369 | 26 ## For example, |
3426 | 27 ## |
3369 | 28 ## @example |
29 ## @group | |
30 ## rot90 ([1, 2; 3, 4], -1) | |
31 ## @result{} 3 1 | |
32 ## 4 2 | |
33 ## @end group | |
34 ## @end example | |
3426 | 35 ## |
3369 | 36 ## @noindent |
37 ## rotates the given matrix clockwise by 90 degrees. The following are all | |
38 ## equivalent statements: | |
3426 | 39 ## |
3369 | 40 ## @example |
41 ## @group | |
42 ## rot90 ([1, 2; 3, 4], -1) | |
43 ## rot90 ([1, 2; 3, 4], 3) | |
44 ## rot90 ([1, 2; 3, 4], 7) | |
45 ## @end group | |
46 ## @end example | |
4869 | 47 ## |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
48 ## Note that @code{rot90} only works with 2-D arrays. To rotate N-D arrays |
4869 | 49 ## use @code{rotdim} instead. |
5642 | 50 ## @seealso{rotdim, flipud, fliplr, flipdim} |
3369 | 51 ## @end deftypefn |
4 | 52 |
2314 | 53 ## Author: jwe |
54 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
55 function B = rot90 (A, k) |
4 | 56 |
4869 | 57 if (nargin == 1 || nargin == 2) |
58 if (nargin < 2) | |
59 k = 1; | |
60 endif | |
4 | 61 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
62 if (ndims (A) > 2) |
8664 | 63 error ("rot90: Only works with 2-D arrays"); |
4869 | 64 endif |
4 | 65 |
4869 | 66 if (imag (k) != 0 || fix (k) != k) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11469
diff
changeset
|
67 error ("rot90: K must be an integer"); |
4869 | 68 endif |
69 | |
4 | 70 k = rem (k, 4); |
4869 | 71 |
4 | 72 if (k < 0) |
73 k = k + 4; | |
74 endif | |
4869 | 75 |
4 | 76 if (k == 0) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
77 B = A; |
4 | 78 elseif (k == 1) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
79 B = flipud (A.'); |
4 | 80 elseif (k == 2) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
81 B = flipud (fliplr (A)); |
4 | 82 elseif (k == 3) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
83 B = (flipud (A)).'; |
4 | 84 else |
85 error ("rot90: internal error!"); | |
86 endif | |
87 else | |
6046 | 88 print_usage (); |
4 | 89 endif |
90 | |
91 endfunction | |
7411 | 92 |
93 %!test | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
94 %! x1 = [1, 2; 3, 4]; |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
95 %! x2 = [2, 4; 1, 3]; |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
96 %! x3 = [4, 3; 2, 1]; |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
97 %! x4 = [3, 1; 4, 2]; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
98 %! |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
99 %! assert(rot90 (x1) == x2); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
100 %! assert(rot90 (x1, 2) == x3); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
101 %! assert(rot90 (x1, 3) == x4); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
102 %! assert(rot90 (x1, 4) == x1); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
103 %! assert(rot90 (x1, 5) == x2); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
104 %! assert(rot90 (x1, -1) == x4); |
7411 | 105 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
106 %% Test input validation |
7411 | 107 %!error rot90 (); |
108 %!error rot90 (1, 2, 3); | |
109 |