changeset 1613:fdcd3e66496e octave-forge

Better heuristic for differing bin widths
author pkienzle
date Mon, 02 Aug 2004 05:25:01 +0000
parents 0e0030483f37
children 15d2212f6777
files main/statistics/histfit.m
diffstat 1 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/main/statistics/histfit.m	Mon Aug 02 05:10:02 2004 +0000
+++ b/main/statistics/histfit.m	Mon Aug 02 05:25:01 2004 +0000
@@ -49,8 +49,7 @@
 endif
 
 [n,xbin]=hist(data,nbins);
-dx = xbin(2)-xbin(1);
-if any(abs(diff(xbin,2)) > 10*dx*eps)
+if any(abs(diff(xbin,2)) > 10*max(xbin)*eps)
   error("histfit bins must be uniform width");
 endif
 
@@ -59,7 +58,8 @@
 x=(-3*sr+mr:0.1*sr:3*sr+mr)';## Evenly spaced samples of the expected data range.
 [xb,yb] = bar(xbin,n);
 y = normal_pdf(x,mr,sr);  
-y = row*y*dx;   ## Normalization necessary to overplot the histogram.
+binwidth = xbin(2)-xbin(1);
+y = row*y*binwidth;   ## Normalization necessary to overplot the histogram.
 plot(xb,yb,";;b",x,y,";;r-");     ## Plots density line over histogram.
 
 endfunction