Mercurial > hg > octave-nkf
diff scripts/general/flipdim.m @ 10790:01f1643dfbb1
fix flipdim with trailing singleton dims
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 15 Jul 2010 12:15:14 +0200 |
parents | b32a0214a464 |
children | 693e22af08ae |
line wrap: on
line diff
--- a/scripts/general/flipdim.m +++ b/scripts/general/flipdim.m @@ -45,17 +45,12 @@ nd = ndims (x); if (nargin == 1) ## Find the first non-singleton dimension. - dim = find (size (x) > 1, 1); - if (isempty (dim)) - dim = 1; - endif - else - if (! (isscalar (dim) && isindex (dim, nd))) - error ("flipdim: DIM must be an integer and a valid dimension"); - endif + [~, dim] = min (size (x) != 1); + elseif (! (isscalar (dim) && isindex (dim))) + error ("flipdim: DIM must be a positive integer"); endif - idx(1:nd) = {':'}; + idx(1:max(nd, dim)) = {':'}; idx{dim} = size (x, dim):-1:1; y = x(idx{:});