diff scripts/statistics/base/skewness.m @ 10669:cab3b148d4e4

Improve validation of input arguments for base statistics functions.
author Rik <octave@nomad.inbox5.com>
date Thu, 27 May 2010 20:12:51 -0700
parents 95c3e38098bf
children 693e22af08ae
line wrap: on
line diff
--- a/scripts/statistics/base/skewness.m	Thu May 27 12:13:28 2010 -0700
+++ b/scripts/statistics/base/skewness.m	Thu May 27 20:12:51 2010 -0700
@@ -49,29 +49,25 @@
     print_usage ();
   endif
 
+  if (!ismatrix(x) || ischar(x))
+    error ("skewness: X must be a numeric matrix or vector");
+  endif
+
   nd = ndims (x);
   sz = size (x);
   if (nargin != 2)
     ## Find the first non-singleton dimension.
-    dim  = 1;
-    while (dim < nd + 1 && sz(dim) == 1)
-      dim = dim + 1;
-    endwhile
-    if (dim > nd)
+    dim = find (sz > 1, 1);
+    if (isempty (dim))
       dim = 1;
     endif
   else
-    if (! (isscalar (dim) && dim == round (dim))
-        && dim > 0
-        && dim < (nd + 1))
-      error ("skewness: dim must be an integer and valid dimension");
+    if (!(isscalar (dim) && dim == round (dim)) || 
+        !(1 <= dim && dim <= nd))
+      error ("skewness: DIM must be an integer and a valid dimension");
     endif
   endif
 
-  if (! ismatrix (x))
-    error ("skewness: x has to be a matrix or a vector");
-  endif
-
   c = sz(dim);
   idx = ones (1, nd);
   idx (dim) = c;