octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #60482] hist() misses error for non-numeric in


From: Arun Giridhar
Subject: [Octave-bug-tracker] [bug #60482] hist() misses error for non-numeric input
Date: Tue, 29 Mar 2022 21:08:05 -0400 (EDT)

Follow-up Comment #12, bug #60482 (project octave):

Here is a patch for this old report:


diff -r 1bddc0ddea74 scripts/plot/draw/hist.m
--- a/scripts/plot/draw/hist.m  Tue Mar 29 16:15:21 2022 -0700
+++ b/scripts/plot/draw/hist.m  Tue Mar 29 21:02:20 2022 -0400
@@ -122,6 +122,15 @@
 
   ## Process possible second argument
   if (nargin == 1 || ischar (varargin{iarg}))
+    ## Require numeric bins if output argument is specified
+    tmp = varargin{iarg}
+    if (nargout >= 1          # output specified
+        && nargin == 2        # this check will not apply for more than 2
input args
+        && ! isnumeric (tmp)) # likely a character input
+          error ("hist: second argument must be numeric when seeking return
value");
+    end
+    ## If here, no major problem, so continue with default bins
+
     n = 10;
     ## Use integer range values and perform division last to preserve
     ## accuracy.


New behavior:

octave:1> data = "ABBCCCDDDDEEEEE", u = unique(data)
data = ABBCCCDDDDEEEEE
u = ABCDE

octave:2> freq = hist (data, u)
tmp = ABCDE
error: hist: second argument must be numeric when seeking return value
error: called from
    hist at line 130 column 11

octave:3> freq = hist (data+0, u)
tmp = ABCDE
error: hist: second argument must be numeric when seeking return value
error: called from
    hist at line 130 column 11

octave:4> freq = hist (data+0, u+0)
freq =

   1   2   3   4   5




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?60482>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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