diff scripts/general/postpad.m @ 10690:35adf2a71f3f

Use common code block to find first non-singleton dimension.
author Rik <octave@nomad.inbox5.com>
date Tue, 08 Jun 2010 22:09:25 -0700
parents d1978e7364ad
children fe3c3dfc07eb
line wrap: on
line diff
--- a/scripts/general/postpad.m	Tue Jun 08 21:59:16 2010 -0700
+++ b/scripts/general/postpad.m	Tue Jun 08 22:09:25 2010 -0700
@@ -18,7 +18,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} postpad (@var{x}, @var{l}, @var{c})
+## @deftypefn  {Function File} {} postpad (@var{x}, @var{l}, @var{c})
 ## @deftypefnx {Function File} {} postpad (@var{x}, @var{l}, @var{c}, @var{dim})
 ## @seealso{prepad, resize}
 ## @end deftypefn
@@ -43,18 +43,15 @@
   nd = ndims (x);
   sz = size (x);
   if (nargin < 4)
-    %% Find the first non-singleton dimension
-    dim  = 1;
-    while (dim < nd + 1 && sz (dim) == 1)
-      dim = dim + 1;
-    endwhile
-    if (dim > nd)
+    ## Find the first non-singleton dimension
+    dim = find (sz > 1, 1);
+    if (isempty (dim))
       dim = 1;
     endif
   else
-    if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && 
-        dim < (nd + 1))
-      error ("postpad: dim must be an integer and valid dimension");
+    if (!(isscalar (dim) && dim == fix (dim)) || 
+        !(1 <= dim && dim <= nd))
+      error ("postpad: DIM must be an integer and a valid dimension");
     endif
   endif