bugGNU Octave - Bugs: bug #32863, x.y.z syntax for structure fails...

 
 

bug #32863: x.y.z syntax for structure fails ("scalar cannot be indexed with .")

Submitted by:  None
Submitted on:  Sun 20 Mar 2011 11:34:55 AM UTC  
 
Category: NoneSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Documentation
Status: InvalidAssigned to: None
Originator Name: Jonathan SchachterOriginator Email: -unavailable-
Open/Closed: ClosedRelease: 3.2.4
Operating System: Microsoft Windows

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Thu 24 Mar 2011 12:21:54 AM UTC, comment #6:

If you're goal was to mimic a hash-like structure you can arrange to do that by careful ordering of assignments. See below.

Also, you might want to be aware of the () notation which allows you to use variables in place of explicit labels. For example,

Rik <rik5>
Project Administrator
Wed 23 Mar 2011 09:04:30 AM UTC, comment #5:

And I agree with that behavior.

Marco

Marco Caliari <caliari>
Project Member
Tue 22 Mar 2011 08:30:26 PM UTC, comment #4:

The suggested behavior from Matlab seems to be the same for Octave.

Rik <rik5>
Project Administrator
Tue 22 Mar 2011 07:50:29 AM UTC, comment #3:

After the warning, I get

See MATLAB 7.0.4 Release Notes, Assigning Nonstructure Variables As Structures Displays Warning for details.

and clicking on it

---------------
signing to a nonstructure variable as if it were a structure is not recommended in MATLAB. For example, if variable x holds a double (as shown below), then attempting to add a fieldname to it, thus converting x to a structure, is not good programming practice and should generate an error.
x = 10;
x.name = magic(3);

Note that if x were empty (i.e., x == []), then assigning a field to it as if it were already a structure is acceptable.
--------------

I'm using 7.6.0.

Marco Caliari <caliari>
Project Member
Mon 21 Mar 2011 08:27:33 PM UTC, comment #2:

Can you point out where exactly in the documentation it says that you can combine the two statements as shown? I did a quick look and I couldn't find it.

Each statement is valid by itself, but they cannot follow each other without clobbering the first assignment. The warning message from Matlab is clearer in this regard.

As a related example,
are both valid assignments, but they can't be combined without generating an error.

Rik <rik5>
Project Administrator
Mon 21 Mar 2011 08:44:38 AM UTC, comment #1:

I confirm this behaviour for 3.4.0 and 3.2.4, while it works in 3.0.5. In ml 7.6.0 it works, but you get the warning

Warning: Struct field assignment overwrites a value with class "double".
See MATLAB 7.0.4 Release Notes, Assigning Nonstructure Variables As Structures Displays Warning for details.

Marco

Marco Caliari <caliari>
Project Member
Sun 20 Mar 2011 11:34:55 AM UTC, original submission:

Either the documentation for structures in the manual is wrong or there is a bug in the way to create structures of structures. The docs say that both of the below are kosher:

x.y = 1
x.y.z = 2

While the first assignment suceeds, the second gives this error:

error: scalar cannot be indexed with .

The relevant section of the docs is "6.1.1 Basic Usage and Examples."

Anonymous

 

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

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by caliari (Posted a comment)
  • -unavailable- added by None (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 24 Mar 2011 12:21:54 AM UTCrik5StatusNeed Info=>Invalid
      Open/ClosedOpen=>Closed
    Mon 21 Mar 2011 08:27:33 PM UTCrik5StatusNone=>Need Info

    Back to the top


    Powered by Savane 3.1-cleanup1