Mercurial > octave-libtiff
changeset 27164:e5f248d614f5
hist.m: Return class for second output which matches Matlab (bug #56465).
* hist.m: Convert a scalar argument for second function parameter (# of bins)
to a double so that second output of hist() will follow the class of the first
argument (data Y). Add BIST tests.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 08 Jun 2019 18:12:32 -0700 |
parents | 47c0b11da31a |
children | 58bdc2d98481 |
files | scripts/plot/draw/hist.m |
diffstat | 1 files changed, 13 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/draw/hist.m Sat Jun 08 16:34:27 2019 -0700 +++ b/scripts/plot/draw/hist.m Sat Jun 08 18:12:32 2019 -0700 @@ -125,8 +125,8 @@ error ("hist: bin specification must be a numeric scalar or vector"); endif - ## Do not convert if input is of class single (or if already is double). - if (! isfloat (x)) + ## Convert integer types or a single specification of N bins to double + if (! isfloat (x) || isscalar (x)) x = double (x); endif @@ -366,6 +366,17 @@ %! assert (nn, [2 0 0 0 0 0 0 0 0 2]); %! assert (xx, 0.5:10); +## Test return class of second output +%!test <*56465> +%! [nn, xx] = hist (double (1:10), single (7)); +%! assert (isa (xx, "double")); +%! [nn, xx] = hist (single (1:10), double (7)); +%! assert (isa (xx, "single")); +%! [nn, xx] = hist (single (1:10), double ([1, 5, 10])); +%! assert (isa (xx, "double")); +%! [nn, xx] = hist (double (1:10), single ([1, 5, 10])); +%! assert (isa (xx, "single")); + ## Test input validation %!error hist () %!error <Y must be real-valued> hist (2+i)