bugGNU Octave - Bugs: bug #60861, set command doesn't allow mixed...

 
 

bug #60861: set command doesn't allow mixed prop/value pairs and cell arrays

Submitter:  None
Submitted:  Wed 30 Jun 2021 05:05:11 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  3 - Low Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Paul Mennen Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * dev
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 01 Aug 2021 01:35:21 AM UTC, comment #3: 

It would be fairly easy to implement in Octave code.  Currently, set() is implemented in C++ (libinterp/corefcn/graphics.cc:12962) and it doesn't look as easy to do this.  The loop in C++ is first over the possible multiple graphics handles in argument 1 and then it dispatches to the correct set method based on whether the additional inputs are cellstrs, a struct, or string/value pairs.

It is probably possible to reverse this and put the for loop over graphics handles inside the decode of one of the three cases of the switch statement.  After that one would need to remove the arguments that were used from args variable and wrap everything in a while loop.

The read-only special cases of set()


 -- VALUE_LIST = set (H, PROPERTY)
 -- ALL_VALUE_LIST = set (H)


would need to be pulled out entirely and probably put at the top of the function.

Rik <rik5>
Group administrator
Wed 21 Jul 2021 08:37:17 AM UTC, comment #2: 

comment #1:

> I believe the issue is that Octave expects either 1) property/value pairs, 2) cell array of properties, cell array of values, or 3) a struct array.  Try `help set`
>


I realize that for simplicity, Octave will often forsake Matlab compatibly for simplicity but in this case it would almost trivial to code the set command so that it was compatible with Matlab. For example, the set command could be written as follows:
 

function r = set(varargin)
  h = varargin{1}
  for k = 2:2:length(varargin)
     sett(h,varargin{k},varargin{k+1});
  end;

 
In this example "set" is the new set command and "sett" is Octave's current implementation of the set command. Of course the best implementation would probably not look like that for efficiency reasons, but this implementation shows that full matlab compatibility for the set command is not far away.

~Paul


Anonymous
Thu 01 Jul 2021 09:11:28 PM UTC, comment #1: 

I believe the issue is that Octave expects either 1) property/value pairs, 2) cell array of properties, cell array of values, or 3) a struct array.  Try `help set`


     There are three ways to give the property names and values:

        * as a comma separated list of PROPERTY, VALUE pairs

          Here, each PROPERTY is a string containing the property name,
          each VALUE is a value of the appropriate type for the
          property.

        * as a cell array of strings PROPERTIES containing property
          names and a cell array VALUES containing property values.

          In this case, the number of columns of VALUES must match the
          number of elements in PROPERTIES.  The first column of VALUES
          contains values for the first entry in PROPERTIES, etc.  The
          number of rows of VALUES must be 1 or match the number of
          elements of H.  In the first case, each handle in H will be
          assigned the same values.  In the latter case, the first
          handle in H will be assigned the values from the first row of
          VALUES and so on.

        * as a structure array PV

          Here, the field names of PV represent the property names, and
          the field values give the property values.  In contrast to the
          previous case, all elements of PV will be set in all handles
          in H independent of the dimensions of PV.


The calling syntax you are using, and which Matlab apparently accepts, is a mix of prop/value pairs and cell arrays.  As you determined, a workaround is to simply separate the individual calls.

You can also join calls if you want into cell arrays.


set (a, {'units', 'position', 'string'}, [repmat({'normalized'}, 3,1), locations, txt])


Rik <rik5>
Group administrator
Wed 30 Jun 2021 05:05:11 PM UTC, original submission:  

Usually the set command allows multiple items, i.e.


set(handle,prop1,value1,prop2,value2,prop3,value3);


Octave usually permits commands like that, however there are two situations where this doesn't work. One is where you are setting a single property to more than one object with different values. (The first set command in the following script is an example of this. A 2nd one is where you are setting multiple properties of a single object. (The second set command in the following script is such an example, and is used to copy both the fontsize and fontweight properties from one object to another):


figure;
locations = {[2 2 2 1]/20; [2 4 2 1]/20; [2 6 2 1]/20};
txt       = {'ABC'; 'DEF'; 'HIJ'};
props     = {'fontsize' 'fontweight'};
a = [uicontrol uicontrol uicontrol];
set(a,'units','normalized',{'position'},locations,{'string'},txt);
set(a(2),props,get(a(1),props),'backgroundcolor','red');


Although this script runs in Matlab, both of these set commands will produce an error such as "argument 0 must be a property name".

There is a fairly easy workaround, which is to simply use only one property/value pair at a time. So if you replace the above two set commands with the following six set commands, the script runs fine with no errors:


set(a,'units','normalized');
set(a,{'position'},locations);
set(a,{'string'},txt);
set(a(2),props,get(a(1),props)); % copies both fontsize and fontweight properties from a(1) to a(2)
set(a(2),'backgroundcolor','red');


I suspect this would not be a difficult bug to fix, but if that turns out not to be the case, I suggest that you at least fix the error message. Almost all error messages I have seen show the routine and line number where the error occurred. However for this particular error message, neither the line number nor the function where the error occurred are displayed. Since my program contains hundreds of set commands it becomes quite laborious to single step thru the code trying to find the set command that Octave was (unjustly) complaining about.

Anonymous

 

(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 rik5 (Posted a comment)
  • -email is unavailable- added by None (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 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-07-06 rik5 Summaryset command sometimes doesn't allow mixed prop/value pairs and cell arrays set command doesn't allow mixed prop/value pairs and cell arrays
    2021-07-01 rik5 CategoryGUI Octave Function
        Priority5 - Normal 3 - Low
        Item GroupNone Matlab Compatibility
        StatusNone Confirmed
        Release6.1.0 dev
        Operating SystemMicrosoft Windows Any
        Summaryset command sometimes doesn't allow multiple items. set command sometimes doesn't allow mixed prop/value pairs and cell arrays

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code