bugGNU Octave - Bugs: bug #63923, hold command to print current...

 
 

bug #63923: hold command to print current status like in Matlab

Submitter:  Tan Siret AKINCI <yutyo>
Submitted:  Mon 13 Mar 2023 10:15:56 PM UTC
   
 
Category:  Octave Function Severity:  1 - Wish
Priority:  3 - Low Item Group:  Feature Request
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 8.1.0 Operating System:  * Any
Fixed Release:  9.1.0 Planned Release:  9.1.0
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 21 Apr 2023 06:53:44 PM UTC, comment #13: 

pushed a simple change to default to the ishold BIST to call hold on instead of hold so it won't echo during tests.

https://hg.savannah.gnu.org/hgweb/octave/rev/61db3c9377fb

Nicholas Jankowski <nrjank>
Group Member
Thu 20 Apr 2023 02:29:22 AM UTC, comment #12: 

I just noticed the test for ishold now echoes 'hold is now on for the current axes' in the log when running 'make check'.  is there a way to suppress the message during testing?

Nicholas Jankowski <nrjank>
Group Member
Thu 06 Apr 2023 11:36:32 PM UTC, comment #11: 

I added an entry in the NEWS file and checked in the patch in comment #6 under jwe's name here: http://hg.savannah.gnu.org/hgweb/octave/rev/72d005398818.

Marking as fixed and closing report.

Rik <rik5>
Group administrator
Mon 20 Mar 2023 07:25:44 AM UTC, comment #10: 

Yes, I'll commit the change.

John W. Eaton <jwe>
Group administrator
Mon 20 Mar 2023 12:30:28 AM UTC, comment #9: 

@jwe: Agree, we could spend days getting the wording right and whether or not to print the message when a semicolon is present or not.  I would just commit your patch from comment #6 (which I tested) and move on.  If this is really problematic we will get new bug reports about the behavior.

Rik <rik5>
Group administrator
Thu 16 Mar 2023 03:28:23 PM UTC, comment #8: 

"I'd suggest not to overthink it."

I'm thinking it's too late for that.

John W. Eaton <jwe>
Group administrator
Thu 16 Mar 2023 03:06:38 PM UTC, comment #7: 

matlab 2022b:

>> blah = hold
Error using hold
Too many output arguments.

>> blah = hold(gca)
Error using hold
Too many output arguments.


And no way to suppress 'hold' toggle message that I can see, whether from CLI or script.

I'd suggest not to overthink it.

Nicholas Jankowski <nrjank>
Group Member
Thu 16 Mar 2023 02:38:42 PM UTC, comment #6: 

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.

John W. Eaton <jwe>
Group administrator
Wed 15 Mar 2023 10:30:40 PM UTC, comment #5: 

Just adding

    turn_hold_off = strcmp (state, "off");

after the last inserted line in Panxto's patch seems to do the trick.

BTW shouldn't there be an option to be able to suppress the printed message e.g., for when hold.m is called in scripts? (or am I overlooking something obvious?)

Philip Nienhuis <philipnienhuis>
Group Member
Wed 15 Mar 2023 03:23:49 PM UTC, comment #4: 

@Pantxo:  Good point.  But don't we still need to define the "turn_hold_off" variable in that IF block?  I didn't add that variable and it is used later in the function.

Could you (or someone) commit the change you proposed with a modification that preserves turn_hold_off?  Thanks!

John W. Eaton <jwe>
Group administrator
Tue 14 Mar 2023 09:07:37 AM UTC, comment #3: 

Since `hold` acts on a specified axes or the current one, I'd remove the mention of the figure and do something like


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
@@ -74,6 +74,11 @@ function hold (varargin)
   hold_all = false;
   if (nargs == 0)
+    state = ifelse (ishold (hax), "off", "on");
+    str = ifelse (hax == gca (), "current", "specified");
+    printf ("hold is now %s for %s axes\n", state, str);
   elseif (nargs == 1)
     state = tolower (varargin{1});
     switch (state)


Pantxo Diribarne <pantxo>
Group Member
Tue 14 Mar 2023 12:14:17 AM UTC, comment #2: 


>> plot(1:3)
>> hold on
>> hold off
>> hold
hold is now on for current figure and axes
>> hold
hold is now off for current figure and axes


that seems to do it.

Nicholas Jankowski <nrjank>
Group Member
Mon 13 Mar 2023 10:57:06 PM UTC, comment #1: 

Is anything more than the attached patch needed?

(file #54482)

John W. Eaton <jwe>
Group administrator
Mon 13 Mar 2023 10:15:56 PM UTC, original submission:  

Hi. I have started to use Octave instead of Matlab a week ago and loved it. One thing that I miss from Matlab is that it used to state if the current plot is held or not when hold command was typed. Is it possible to have hold call ishold() and echo the state after toggling the state?

Thanks for maintaining and developing this software,

Tan Siret AKINCI <yutyo>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #54482:  hold-diffs.txt added by jwe (499B - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by yutyo (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-04-06 rik5 StatusPatch Reviewed Fixed
        Open/ClosedOpen Closed
        Fixed ReleaseNone 9.1.0
    2023-03-20 rik5 Severity3 - Normal 1 - Wish
        Priority5 - Normal 3 - Low
        StatusPatch Submitted Patch Reviewed
        Planned ReleaseNone 9.1.0
    2023-03-15 jwe StatusNone Patch Submitted
    2023-03-13 jwe Attached File- Added hold-diffs.txt, #54482

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code