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

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

[Octave-bug-tracker] [bug #63923] hold command to print current status l


From: John W. Eaton
Subject: [Octave-bug-tracker] [bug #63923] hold command to print current status like in Matlab
Date: Thu, 16 Mar 2023 10:38:42 -0400 (EDT)

Follow-up Comment #6, bug #63923 (project octave):

Instead of using strcmp, we could just use the original turn_hold_off variable
set from the result of ishold.  Also, if hold is called as


hold (gca (), ...)


should the message say "current" or "specified"?  Either is correct, but it
seems like maybe it should say 'specified' since the axes argument was
provided.

So, how about this change?


diff --git a/scripts/plot/util/hold.m b/scripts/plot/util/hold.m
--- a/scripts/plot/util/hold.m
+++ b/scripts/plot/util/hold.m
@@ -58,7 +58,9 @@
 
 function hold (varargin)
 
+  have_axes_arg = false;
   if (nargin > 0 && isscalar (varargin{1}) && isaxes (varargin{1}))
+    have_axes_arg = true;
     hax = varargin{1};
     varargin(1) = [];
     nargs = numel (varargin);
@@ -74,6 +76,9 @@ function hold (varargin)
   hold_all = false;
   if (nargs == 0)
     turn_hold_off = ishold (hax);
+    state_str = ifelse (turn_hold_off, "off", "on");
+    axes_str = ifelse (have_axes_arg, "specified", "current");
+    printf ("hold is now %s for %s axes\n", state_str, axes_str);
   elseif (nargs == 1)
     state = tolower (varargin{1});
     switch (state)


As for suppressing the message, what does Matlab do?  I don't think it allows
hold to be called like this:


hold_state = hold (...);


and if the message is just printed, not returned by the function, then
terminating the expression with a semicolon won't suppress the output.

Then again, if you want to use "hold" in a script or function, you probably
want to specify "on" or "off" to make the behavior of your script predictable.
 Toggling the current state (whatever it might happen to be) is probably not
the best idea.


    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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