octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Modifications to hist.m


From: Andy Adler
Subject: Modifications to hist.m
Date: Sat, 15 Mar 2003 16:09:51 -0500 (EST)

I propose the following patch to hist.m;
it results in about 2.5x speedup.

octave:1> im=rand(500^2,1);
octave:2> jnk= hist(im,100); tic;v1=hist(im,100);toc
ans = 7.1460
octave:3> jnk= hist_orig(im,100);tic;v2=hist_orig(im,100);toc
ans = 17.604
octave:4> std(v1-v2)
ans = 0


$ diff -u hist.m /usr/local/oct2145/share/octave/2.1.45/m/plot/hist.m
--- hist.m      2003-03-15 15:47:16.000000000 -0500
+++ /usr/local/oct2145/share/octave/2.1.45/m/plot/hist.m        2003-02-27
19:22
:32.000000000 -0500
@@ -87,11 +87,12 @@
     endif
   endif

-  cumfreq = [zeros (1, n), length(y) ];
-  for i = 1:n-1
-    cumfreq (i+1) = sum (y < cutoff (i));
-  end
-  freq= diff(cumfreq);
+  freq = zeros (1, n);
+  freq (1) = sum (y < cutoff (1));
+  for i = 2:n-1
+    freq (i) = sum (y >= cutoff (i-1) & y < cutoff (i));
+  endfor
+  freq (n) = sum (y >= cutoff (n-1));

   if (nargin == 3)
     ## Normalise the histogram.


Andy



reply via email to

[Prev in Thread] Current Thread [Next in Thread]