bugGNU Octave - Bugs: bug #59113, Warning when String property of a...

 
 

bug #59113: Warning when String property of a uicontrol is a char array

Submitter:  Guillaume <gyom>
Submitted:  Mon 14 Sep 2020 11:28:20 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
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
   

Jump to the original submission

Tue 22 Sep 2020 09:22:16 PM UTC, comment #10: 

I tested and Octave does not support mixed struct and property/value pairs in line.m.  I suspect that this lack of support is general within Octave.  I will close this bug report and open up a new Matlab compatibility bug about the other behavior.

Rik <rik5>
Group administrator
Mon 21 Sep 2020 07:06:22 PM UTC, comment #9: 

Re-opening bug report.  I forgot that Matlab allowed structs to be presented.  That will make the input validation more cumbersome.  There should also be a BIST test for presenting structs to uicontrol so that we don't miss this again in the future.

Rik <rik5>
Group administrator
Mon 21 Sep 2020 06:49:19 PM UTC, comment #8: 

I'm not sure the change in comment #5 was correct. The input to graphics functions can be a mixture of property value pairs and structures with corresponding fields and values.
E.g. `line ([0, 1], [0, 1], 'LineStyle', ':', struct ('Linewidth', 3), 'Color', 'k')` is valid in Matlab.
The same is probably also true for `uicontrol`.
Matching only every argument might miss the actual one.

Markus Mützel <mmuetzel>
Group administrator
Tue 15 Sep 2020 09:30:01 AM UTC, comment #7: 

Thanks for this, Rik. I confirm it all works fine and the warnings have disappeared.

Guillaume <gyom>
Mon 14 Sep 2020 09:47:06 PM UTC, comment #6: 

I found the last instance of code that was emitting a warning and fixed it in this changeset: http://hg.savannah.gnu.org/hgweb/octave/rev/ffdb29f7baab.

Marking as fixed and closing report.

Rik <rik5>
Group administrator
Mon 14 Sep 2020 07:16:32 PM UTC, comment #5: 

I checked in a change (http://hg.savannah.gnu.org/hgweb/octave/rev/fed3b09f2efc) that fixes 2 out of 3 of the warnings printed when creating a uicontrol object.  It turns out the input validation was not very good and was checking non-string values that it shouldn't have.

Getting rid of the last warning will be a little more difficult.  It is coming from somewhere in the graphics property architecture defined by graphics.in.h.  There is a special string_array_property class which seems to mostly do the right thing, but somewhere it must be calling straight string_value() on a char matrix.

Rik <rik5>
Group administrator
Mon 14 Sep 2020 06:41:59 PM UTC, comment #4: 

Thanks, I was not aware (or had forgotten) what Matlab was doing here. My initial surprise was with this:


strcmp(['a';'b'],'a')
strcmp({['a';'b']},'a')


where Octave throws a warning only in the second case.

Guillaume <gyom>
Mon 14 Sep 2020 05:57:01 PM UTC, comment #3: 

The results for strcmp are what I would expect.  There might be a bug report open about this already, otherwise we could create one to discuss the difference.  Take the second case as being the most straightforward of what is going on.


s = { ['a';'b'], 'a' }


This creates a 1x2 cell array where the first entry is a 2x1 char matrix and the second is a 1x1 char matrix.

Now try


strcmp (s, 'a')


Octave iterates over the cell array.  For the first entry it finds a multi-row char matrix and warns that only the first row will be considered.  That first row is 'a' so the strcmp matches.  The second entry is 'a' by itself which also matches so the return value is "1 1".

Matlab, however, seems to convert a char matrix to a 1xN string before comparison.  The code equivalent is


str = char_mat(:).'


You can see that by testing this


strcmp (s, 'ab')


Matlab will return "1 0" while Octave returns "0 0".

Rik <rik5>
Group administrator
Mon 14 Sep 2020 04:53:37 PM UTC, comment #2: 

Thanks, Rik. When looking into uicontrol to see where the warnings were coming from, I noticed this:


strcmp(char({'a','b'}),'a')
strcmp({char({'a','b'}),'a'},'a')
strcmp(char({'a','b'}),{char({'a','b'}),'a'})


Octave returns:


>> strcmp(char({'a','b'}),'a')
ans = 0
>> strcmp({char({'a','b'}),'a'},'a')
warning: multi-row character matrix converted to a string, only the first row is used
ans =
  1  1
>> strcmp(char({'a','b'}),{char({'a','b'}),'a'})
warning: multi-row character matrix converted to a string, only the first row is used
ans =
  1  0


while Matlab returns:


>> strcmp(char({'a','b'}),'a')
ans =
  logical
   0
>> strcmp({char({'a','b'}),'a'},'a')
ans =
  1x2 logical array
   0   1
>> strcmp(char({'a','b'}),{char({'a','b'}),'a'})
ans =
  1x2 logical array
   0   0


I'll open a separate bug report for pipe-delimited strings.

Guillaume <gyom>
Mon 14 Sep 2020 04:31:38 PM UTC, comment #1: 

Confirmed.  There are two issues here.  The first is the new warning message which isn't needed.  I'll look at that now.

The second is the return value for the "String" property.  Matlab converts the first two examples into 3x1 char arrays while Octave converts to a single pipe-delimited string.  Could you file a new bug report about that?  It looks less urgent to fix as the difference is cosmetic.  Matlab allows the pipe-delimited syntax


set (U, 'String', 'X|Y|Z')


which means code will work interoperably between Octave and Matlab.

Rik <rik5>
Group administrator
Mon 14 Sep 2020 11:28:20 AM UTC, original submission:  

Following bug #49536, the following now displays a warning when the String property is a char array:


F = figure ();
U = uicontrol (F, 'Style','listbox',...
   'Position',[50 100 100 100],...
   'String', char ({'A','B','C'}));
get(U,'String')
U = uicontrol (F, 'Style','listbox',...
   'Position',[200 100 100 100],...
   'String', 'D|E|F');
get(U,'String')
U = uicontrol (F, 'Style','listbox',...
   'Position',[350 100 100 100],...
   'String', {'G','H','I'});
get(U,'String')


Current Matlab documentation does not mention char array as a supported format but I presume it used to be the case before string arrays was introduced:
https://www.mathworks.com/help/matlab/ref/matlab.ui.control.uicontrol-properties.html#mw_9885699e-8fe3-4ebe-a09a-c3258d2104ac
It seems that Octave automatically converts it to pipe-delimited row vector 'A|B|C' while Matlab does the other way round by converting 'D|E|F' into a char array.

I would suggest Octave still allows char arrays for backward compatibility (they can be stored in *.fig files), without displaying a warning.

Guillaume <gyom>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by rik5 (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 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-09-22 rik5 StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2020-09-21 rik5 StatusFixed In Progress
        Open/ClosedClosed Open
    2020-09-14 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2020-09-14 rik5 StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-cf05.
    Corresponding source code