bugGNU Octave - Bugs: bug #49751, Output of uicontrol

 
 

bug #49751: Output of uicontrol

Submitter:  Guillaume <gyom>
Submitted:  Fri 02 Dec 2016 12:58:41 PM UTC
   
 
Category:  Octave Function Severity:  2 - Minor
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Guillaume Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 13 Mar 2017 05:06:31 AM UTC, comment #4: 

I just came across this patch in my e-mail.  I applied it on the development branch here (http://hg.savannah.gnu.org/hgweb/octave/rev/cc9dcadcef6b).  Thanks Guillaume!

Marking as fixed and closing report.

Rik <rik5>
Group administrator
Mon 05 Dec 2016 10:51:59 AM UTC, comment #3: 

Thanks. I've checked all ui* functions and made adjustments when needed for better compatibility with Matlab.

There is one function I didn't change: uiwait. In Octave, as documented, the function returns immediately if there is no input and no current figure. In this context, Matlab creates a new figure (as described in its documentation).

https://www.mathworks.com/help/matlab/ref/uiwait.html

(file #39146)

Guillaume <gyom>
Fri 02 Dec 2016 05:26:30 PM UTC, comment #2: 

No objections to making such a change.  Take a look at how this is done for the scripts in the plot/draw directory.  As just one example, here is waterfall.m:


function h = waterfall (varargin)

  htmp = meshz (varargin{:});

  set (htmp, "meshstyle", "row");

  if (nargout > 0)
    h = htmp;
  endif

endfunction


The code uses 'htmp' rather than tmp so that it is clear that the underlying variable is a handle.  Otherwise, 'tmp' might be an integer, a string, who knows?

In this case the function is so short one wouldn't become confused, but it is still good practice.

Also, in this case the documentation refers to the return value as 'hui' so the code should use that variable as well.


  if (nargout > 0)
    hui = htmp;
  endif


Does Matlab avoid returning the handle if there is no output argument for all uiXXX functions?  If so, we should implement the--easy--change across all the uiXX functions in scripts/gui/.


Rik <rik5>
Group administrator
Fri 02 Dec 2016 03:06:11 PM UTC, comment #1: 

Since uicontrol will never return more than one argument, varargout is not useful, the second (H=htmp) is thus more clear.

Pantxo Diribarne <pantxo>
Group Member
Fri 02 Dec 2016 12:58:41 PM UTC, original submission:  

This is a small suggestion to have uicontrol only return a handle when explicitly requested, in alignment with Matlab's behavior.

I used the same mechanism as in uimenu but I wonder what is the recommended way to proceed:


function varargout = fcn (varargin)
  varargout = {};
  H = ...
  if (nargout > 0)
    varargout = {H};
  endif
endfunction


instead of:


function H = fcn (varargin)
  tmp = ...
  if (nargout > 0)
    H = tmp;
  endif
endfunction


Guillaume <gyom>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #39146:  patch_ui.diff added by gyom (6KiB - application/x-download)
file #39132:  fix_uicontrol.diff added by gyom (480B - application/x-download)

 

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 gyom (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 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-03-13 rik5 StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2016-12-05 gyom Attached File- Added patch_ui.diff, #39146
    2016-12-02 rik5 Severity3 - Normal 2 - Minor
        StatusNone In Progress
    2016-12-02 gyom Attached File- Added fix_uicontrol.diff, #39132

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code