Mercurial > hg > octave-kai
changeset 9508:e5e4e404a59d
simplify flipdim
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 07 Aug 2009 08:46:51 +0200 |
parents | b096d11237be |
children | c5330ef7aecd |
files | scripts/ChangeLog scripts/general/flipdim.m |
diffstat | 2 files changed, 11 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2009-08-07 Jaroslav Hajek <highegg@gmail.com> + + * general/flipdim.m: Simplify. + 2009-08-07 Olli Saarela <olli.saarela@gmail.com> * plot/__gnuplot_ginput__.m: If read fails to return data, sleep
--- a/scripts/general/flipdim.m +++ b/scripts/general/flipdim.m @@ -1,4 +1,5 @@ ## Copyright (C) 2004, 2005, 2006, 2007 David Bateman +## Copyright (C) 2009 VZLU Prague ## ## This file is part of Octave. ## @@ -31,7 +32,7 @@ ## @seealso{fliplr, flipud, rot90, rotdim} ## @end deftypefn -## Author: David Bateman +## Author: David Bateman, Jaroslav Hajek function y = flipdim (x, dim) @@ -40,27 +41,20 @@ endif nd = ndims (x); - sz = size (x); if (nargin == 1) ## Find the first non-singleton dimension. - dim = 1; - while (dim < nd + 1 && sz(dim) == 1) - dim = dim + 1; - endwhile - if (dim > nd) + dim = find (size (x) != 1, 1); + if (isempty (dim)) dim = 1; endif else - if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && dim < (nd + 1)) + if (! isindex (dim, nd)) error ("flipdim: dim must be an integer and valid dimension"); endif endif - idx = cell (); - for i = 1:nd - idx{i} = 1:sz(i); - endfor - idx{dim} = sz(dim):-1:1; + idx(1:nd) = {':'}; + idx{dim} = size (x, dim):-1:1; y = x(idx{:}); endfunction