Mercurial > octave
changeset 25631:d1216d085280
maint: merge stable to default.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 17 Jul 2018 08:58:10 -0700 |
parents | f092ffdc7770 (current diff) b96ab99e67bb (diff) |
children | f89bf246dcd4 |
files | |
diffstat | 1 files changed, 16 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/draw/hist.m Mon Jul 16 12:34:10 2018 -0700 +++ b/scripts/plot/draw/hist.m Tue Jul 17 08:58:10 2018 -0700 @@ -108,8 +108,12 @@ if (nargin == 1 || ischar (varargin{iarg})) n = 10; ## Use range type to preserve accuracy - x = (0.5:n) * (1/n); - x = (max_val - min_val) * x + min_val; + if (min_val != max_val) + x = (0.5:n) * (1/n); + x = (max_val - min_val) * x + min_val; + else + x = (-floor ((n-1)/2):ceil ((n-1)/2)) + min_val; + endif x = x.'; # Convert to matrix; else ## Parse bin specification argument @@ -129,8 +133,12 @@ error ("hist: number of bins NBINS must be positive"); endif ## Use range type to preserve accuracy - x = (0.5:n) * (1/n); - x = (max_val - min_val) * x + min_val; + if (min_val != max_val) + x = (0.5:n) * (1/n); + x = (max_val - min_val) * x + min_val; + else + x = (-floor ((n-1)/2):ceil ((n-1)/2)) + min_val; + endif x = x.'; # Convert to matrix; elseif (isvector (x)) x = x(:); @@ -233,6 +241,10 @@ %! assert (sum (hist ([1:n], 30)), n); %! endfor %!assert (hist (1,1), 1) +%!test <*54326> # All values identical +%! [nn,xx] = hist (ones (1,5), 3); +%! assert (nn, [0,5,0]); +%! assert (xx, [0,1,2]); %!assert (size (hist (randn (750,240), 200)), [200, 240]) %!assert <*42394> (isempty (hist (rand (10,2), 0:5, 1)), false) %!assert <*42394> (isempty (hist (rand (10,2), 0:5, [1 1])), false)