Mercurial > octave-antonio
annotate scripts/deprecated/flipdim.m @ 19126:995df67fc912
Flip arrays - ND support for fliplr and flipud, and replace flipdim with flip.
* fliplr.m, flipud.m: add support for N-dimensional arrays by making use
of flip(). Added new tests for ND arrays and defaults.
* flipdim.m: deprecate in favour of new function flip() which has exactly the
same syntax and is part of Matlab since R2014a.
* flip.m: new function copied from flipdim. Added tests for ND arrays and
defaults.
* matrix.txi: replace flipdim DOCSTRINg with flip.
* rot90.m, rotdim.m, del2.m: replace flipdim() with flip()
* NEWS: note deprecation of flip(), new function flipdim(), and ND support
for flipud() and fliplr().
author | Carnë Draug <carandraug+dev@gmail.com> |
---|---|
date | Sun, 21 Sep 2014 18:49:08 +0100 |
parents | scripts/general/flipdim.m@7bbe3658c5ef |
children |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
1 ## Copyright (C) 2004-2013 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. |
5012 | 25 ## |
19126
995df67fc912
Flip arrays - ND support for fliplr and flipud, and replace flipdim with flip.
Carnë Draug <carandraug+dev@gmail.com>
parents:
18857
diff
changeset
|
26 ## @strong{Warning:} @code{flipdim} is scheduled for removal in version 4.6. |
995df67fc912
Flip arrays - ND support for fliplr and flipud, and replace flipdim with flip.
Carnë Draug <carandraug+dev@gmail.com>
parents:
18857
diff
changeset
|
27 ## Use @code{flip} which can be used as a drop-in replacement. |
995df67fc912
Flip arrays - ND support for fliplr and flipud, and replace flipdim with flip.
Carnë Draug <carandraug+dev@gmail.com>
parents:
18857
diff
changeset
|
28 ## |
5642 | 29 ## @seealso{fliplr, flipud, rot90, rotdim} |
5012 | 30 ## @end deftypefn |
31 | |
9508 | 32 ## Author: David Bateman, Jaroslav Hajek |
5012 | 33 |
34 function y = flipdim (x, dim) | |
35 | |
19126
995df67fc912
Flip arrays - ND support for fliplr and flipud, and replace flipdim with flip.
Carnë Draug <carandraug+dev@gmail.com>
parents:
18857
diff
changeset
|
36 persistent warned = false; |
995df67fc912
Flip arrays - ND support for fliplr and flipud, and replace flipdim with flip.
Carnë Draug <carandraug+dev@gmail.com>
parents:
18857
diff
changeset
|
37 if (! warned) |
995df67fc912
Flip arrays - ND support for fliplr and flipud, and replace flipdim with flip.
Carnë Draug <carandraug+dev@gmail.com>
parents:
18857
diff
changeset
|
38 warned = true; |
995df67fc912
Flip arrays - ND support for fliplr and flipud, and replace flipdim with flip.
Carnë Draug <carandraug+dev@gmail.com>
parents:
18857
diff
changeset
|
39 warning ("Octave:deprecated-function", |
995df67fc912
Flip arrays - ND support for fliplr and flipud, and replace flipdim with flip.
Carnë Draug <carandraug+dev@gmail.com>
parents:
18857
diff
changeset
|
40 "flipdim is deprecated and will be removed from a future version of Octave; please use flip (x, dim) instead"); |
995df67fc912
Flip arrays - ND support for fliplr and flipud, and replace flipdim with flip.
Carnë Draug <carandraug+dev@gmail.com>
parents:
18857
diff
changeset
|
41 endif |
995df67fc912
Flip arrays - ND support for fliplr and flipud, and replace flipdim with flip.
Carnë Draug <carandraug+dev@gmail.com>
parents:
18857
diff
changeset
|
42 |
5012 | 43 if (nargin != 1 && nargin != 2) |
6046 | 44 print_usage (); |
5012 | 45 endif |
46 | |
47 nd = ndims (x); | |
12796
886256714823
codesprint: Correct missing comma in tests for flipdim.m
Rik <octave@nomad.inbox5.com>
parents:
12795
diff
changeset
|
48 sz = size (x); |
5012 | 49 if (nargin == 1) |
50 ## 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
|
51 (dim = find (sz > 1, 1)) || (dim = 1); |
10790
01f1643dfbb1
fix flipdim with trailing singleton dims
Jaroslav Hajek <highegg@gmail.com>
parents:
10692
diff
changeset
|
52 elseif (! (isscalar (dim) && isindex (dim))) |
01f1643dfbb1
fix flipdim with trailing singleton dims
Jaroslav Hajek <highegg@gmail.com>
parents:
10692
diff
changeset
|
53 error ("flipdim: DIM must be a positive integer"); |
5012 | 54 endif |
55 | |
10790
01f1643dfbb1
fix flipdim with trailing singleton dims
Jaroslav Hajek <highegg@gmail.com>
parents:
10692
diff
changeset
|
56 idx(1:max(nd, dim)) = {':'}; |
9508 | 57 idx{dim} = size (x, dim):-1:1; |
5012 | 58 y = x(idx{:}); |
59 | |
60 endfunction | |
12795
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12674
diff
changeset
|
61 |