Mercurial > hg > octave-nkf
annotate scripts/general/flipdim.m @ 9665:1dba57e9d08d
use blas_trans_type for xgemm
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 26 Sep 2009 10:41:07 +0200 |
parents | 1b290ce305fb |
children | b32a0214a464 |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 2004, 2005, 2006, 2007 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 -*- | |
21 ## @deftypefn {Function File} {} flipdim (@var{x}, @var{dim}) | |
22 ## Return a copy of @var{x} flipped about the dimension @var{dim}. | |
5018 | 23 ## For example |
5012 | 24 ## |
25 ## @example | |
26 ## @group | |
27 ## flipdim ([1, 2; 3, 4], 2) | |
28 ## @result{} 2 1 | |
29 ## 4 3 | |
30 ## @end group | |
31 ## @end example | |
5642 | 32 ## @seealso{fliplr, flipud, rot90, rotdim} |
5012 | 33 ## @end deftypefn |
34 | |
9508 | 35 ## Author: David Bateman, Jaroslav Hajek |
5012 | 36 |
37 function y = flipdim (x, dim) | |
38 | |
39 if (nargin != 1 && nargin != 2) | |
6046 | 40 print_usage (); |
5012 | 41 endif |
42 | |
43 nd = ndims (x); | |
44 if (nargin == 1) | |
45 ## Find the first non-singleton dimension. | |
9508 | 46 dim = find (size (x) != 1, 1); |
47 if (isempty (dim)) | |
5012 | 48 dim = 1; |
49 endif | |
50 else | |
9510
1b290ce305fb
add omitted check in flipdim
Jaroslav Hajek <highegg@gmail.com>
parents:
9508
diff
changeset
|
51 if (! (isscalar (dim) && isindex (dim, nd))) |
5012 | 52 error ("flipdim: dim must be an integer and valid dimension"); |
53 endif | |
54 endif | |
55 | |
9508 | 56 idx(1:nd) = {':'}; |
57 idx{dim} = size (x, dim):-1:1; | |
5012 | 58 y = x(idx{:}); |
59 | |
60 endfunction |