Mercurial > hg > octave-nkf
annotate scripts/general/flipdim.m @ 15107:03381a36f70d
generate convenience libraries for new parse-tree and interpfcn subdirectories
* src/Makefile.am (liboctinterp_la_SOURCES): Include octave.cc in the
list, not $(DIST_SRC).
(liboctinterp_la_LIBADD): Include octave-value/liboctave-value.la,
parse-tree/libparse-tree.la, interp-core/libinterp-core.la,
interpfcn/libinterpfcn.la, and corefcn/libcorefcn.la in the list.
* src/interp-core/module.mk (noinst_LTLIBRARIES): Add
interp-core/libinterp-core.la to the list.
(interp_core_libinterp_core_la_SOURCES): New variable.
* src/interpfcn/module.mk (noinst_LTLIBRARIES): Add
interpfcn/libinterpfcn.la to the list.
(interpfcn_libinterpfcn_la_SOURCES): New variable.
* src/parse-tree/module.mk (noinst_LTLIBRARIES): Add
parse-tree/libparse-tree.la to the list.
(parse_tree_libparse_tree_la_SOURCES): New variable.
* src/octave-value/module.mk (noinst_LTLIBRARIES): Add
octave-value/liboctave-value.la to the list.
(octave_value_liboctave_value_la_SOURCES): New variable.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 05 Aug 2012 09:04:30 -0400 |
parents | f3d52523cde1 |
children | d63878346099 bf27e21f0bfb |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12796
diff
changeset
|
1 ## Copyright (C) 2004-2012 David Bateman |
9508 | 2 ## Copyright (C) 2009 VZLU Prague |
5012 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
5012 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
5012 | 19 |
20 ## -*- texinfo -*- | |
10692
b32a0214a464
Use > 1 test to find first non-singleton dimension rather than != 1.
Rik <octave@nomad.inbox5.com>
parents:
9510
diff
changeset
|
21 ## @deftypefn {Function File} {} flipdim (@var{x}) |
b32a0214a464
Use > 1 test to find first non-singleton dimension rather than != 1.
Rik <octave@nomad.inbox5.com>
parents:
9510
diff
changeset
|
22 ## @deftypefnx {Function File} {} flipdim (@var{x}, @var{dim}) |
5012 | 23 ## Return a copy of @var{x} flipped about the dimension @var{dim}. |
10692
b32a0214a464
Use > 1 test to find first non-singleton dimension rather than != 1.
Rik <octave@nomad.inbox5.com>
parents:
9510
diff
changeset
|
24 ## @var{dim} defaults to the first non-singleton dimension. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10790
diff
changeset
|
25 ## For example: |
5012 | 26 ## |
27 ## @example | |
28 ## @group | |
29 ## flipdim ([1, 2; 3, 4], 2) | |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
30 ## @result{} 2 1 |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
31 ## 4 3 |
5012 | 32 ## @end group |
33 ## @end example | |
5642 | 34 ## @seealso{fliplr, flipud, rot90, rotdim} |
5012 | 35 ## @end deftypefn |
36 | |
9508 | 37 ## Author: David Bateman, Jaroslav Hajek |
5012 | 38 |
39 function y = flipdim (x, dim) | |
40 | |
41 if (nargin != 1 && nargin != 2) | |
6046 | 42 print_usage (); |
5012 | 43 endif |
44 | |
45 nd = ndims (x); | |
12796
886256714823
codesprint: Correct missing comma in tests for flipdim.m
Rik <octave@nomad.inbox5.com>
parents:
12795
diff
changeset
|
46 sz = size (x); |
5012 | 47 if (nargin == 1) |
48 ## Find the first non-singleton dimension. | |
12674
9493880928c8
Use common idiom in m-files for finding first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
49 (dim = find (sz > 1, 1)) || (dim = 1); |
10790
01f1643dfbb1
fix flipdim with trailing singleton dims
Jaroslav Hajek <highegg@gmail.com>
parents:
10692
diff
changeset
|
50 elseif (! (isscalar (dim) && isindex (dim))) |
01f1643dfbb1
fix flipdim with trailing singleton dims
Jaroslav Hajek <highegg@gmail.com>
parents:
10692
diff
changeset
|
51 error ("flipdim: DIM must be a positive integer"); |
5012 | 52 endif |
53 | |
10790
01f1643dfbb1
fix flipdim with trailing singleton dims
Jaroslav Hajek <highegg@gmail.com>
parents:
10692
diff
changeset
|
54 idx(1:max(nd, dim)) = {':'}; |
9508 | 55 idx{dim} = size (x, dim):-1:1; |
5012 | 56 y = x(idx{:}); |
57 | |
58 endfunction | |
12795
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12674
diff
changeset
|
59 |
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12674
diff
changeset
|
60 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
61 %!assert (flipdim ([1,2;3,4]), flipdim ([1,2 ; 3,4], 1)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
62 %!assert (flipdim ([1,2;3,4], 2), [2,1;4,3]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
63 %!assert (flipdim ([1,2;3,4], 3), [1,2;3,4]) |
12795
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12674
diff
changeset
|
64 |
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12674
diff
changeset
|
65 ## FIXME -- we need tests for multidimensional arrays. |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
66 |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
67 %!error flipdim () |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
68 %!error flipdim (1, 2, 3) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
69 |