changeset 18811:9040ad7feb35 stable

Fix regression in hist with multiple columns and normalization (bug #42394). * hist.m: Use bsxfun to expand out normalization constant from scalar to vector if necessary. Add %!tests for correct behavior.
author Rik <rik@octave.org>
date Fri, 23 May 2014 13:25:20 -0700
parents d99475e26c78
children 6e2b1de8348e
files scripts/plot/draw/hist.m
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/draw/hist.m	Fri May 23 13:04:57 2014 -0700
+++ b/scripts/plot/draw/hist.m	Fri May 23 13:25:20 2014 -0700
@@ -157,7 +157,7 @@
   if (nargin > 2 && ! ischar (varargin{iarg}))
     ## Normalize the histogram.
     norm = varargin{iarg++};
-    freq *= norm / sum (! isnan (y));
+    freq = bsxfun (@times, freq, norm ./ sum (! isnan (y)));
   endif
 
   if (nargout > 0)
@@ -209,4 +209,6 @@
 %! endfor
 %!assert (hist (1,1), 1)
 %!assert (size (hist (randn (750,240), 200)), [200,240])
-
+## Test bug #42394
+%!assert (isempty (hist (rand (10,2), 0:5, 1)), false)
+%!assert (isempty (hist (rand (10,2), 0:5, [1 1])), false)