changeset 11335:db091f68798c

allow kolmogorov_smirnov_test to work with either DIST_cdf or DISTcdf functions
author John W. Eaton <jwe@octave.org>
date Thu, 09 Dec 2010 18:59:23 -0500
parents 703f51c2beb7
children 5a4a7febe37c
files scripts/ChangeLog scripts/statistics/tests/kolmogorov_smirnov_test.m
diffstat 2 files changed, 27 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Thu Dec 09 18:36:41 2010 -0500
+++ b/scripts/ChangeLog	Thu Dec 09 18:59:23 2010 -0500
@@ -1,3 +1,9 @@
+2010-12-09  John W. Eaton  <jwe@octave.org>
+
+	* statistics/tests/kolmogorov_smirnov_test.m: Try both DIST_cdf
+	and DISTcdf functions.  Always use feval to call CDF function.
+	Bug #31838.
+
 2010-12-09  John W. Eaton  <jwe@octave.org>
 
 	* plot/__go_draw_axes__.m: Set major and grid linewidths from
--- a/scripts/statistics/tests/kolmogorov_smirnov_test.m	Thu Dec 09 18:36:41 2010 -0500
+++ b/scripts/statistics/tests/kolmogorov_smirnov_test.m	Thu Dec 09 18:59:23 2010 -0500
@@ -29,7 +29,7 @@
 ## a uniform distribution on [2,4], use
 ##
 ## @example
-## kolmogorov_smirnov_test(x, "uniform", 2, 4)
+## kolmogorov_smirnov_test(x, "unif", 2, 4)
 ## @end example
 ##
 ## @noindent
@@ -66,25 +66,31 @@
 
   n = length (x);
   s = sort (x);
-  f = str2func (sprintf ("%s_cdf", dist));
+  try
+    f = str2func (sprintf ("%scdf", dist));
+  catch
+    try
+      f = str2func (sprintf ("%s_cdf", dist));
+    catch
+      error ("kolmogorov_smirnov_test: no %scdf or %s_cdf function found",
+             dist, dist);
+    end_try_catch
+  end_try_catch
 
   alt  = "!=";
 
-  if (nargin == 2)
-    z = reshape (feval (f, s), 1, n);
-  else
-    args = "";
-    for k = 1 : (nargin-2);
-      tmp  = varargin{k};
-      if ischar (tmp)
-        alt = tmp;
-      else
-        args = sprintf ("%s, %g", args, tmp);
-      endif
-    endfor
-    z = reshape (eval (sprintf ("%s(s%s);", func2str (f), args)), 1, n);
+  args{1} = s;
+  nvargs = numel (varargin);
+  if (nvargs > 0)
+    if (ischar (varargin{end}))
+      args(2:nvargs) = varargin(1:end-1);
+    else
+      args(2:nvargs+1) = varargin;
+    endif
   endif
 
+  z = reshape (feval (f, args{:}), 1, n);
+
   if (strcmp (alt, "!=") || strcmp (alt, "<>"))
     ks   = sqrt (n) * max (max ([abs(z - (0:(n-1))/n); abs(z - (1:n)/n)]));
     pval = 1 - kolmogorov_smirnov_cdf (ks);