octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

structure discussion


From: Colin Ingram
Subject: structure discussion
Date: Tue, 11 Oct 2005 13:45:16 -0500
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041206 Thunderbird/1.0 Mnenhy/0.7.2.0

Is this a bug?

octave:57> g(1).a = 4
                 g =
                 {
                   a = 4
                 }

octave:58> g(3).a = 5
                 g =
                 {
                   a =

                   (,
                     [1] = 4
                     [2] = [](0x0)
                     [3] = 5
                   ,)

                 }

octave:59> g(:).b = "string"
                 g =
                 {
                   a =

                   (,
                     [1] = 4
                     [2] = [](0x0)
                     [3] = 5
                   ,)

                   b =

                   (,
                     [1] = string
                     [2] = [](0x0)
                     [3] = [](0x0)
                   ,)

                 }

octave:60> g(:).b = 4
                 g =
                 {
                   a =

                   (,
                     [1] = 4
                     [2] = [](0x0)
                     [3] = 5
                   ,)

                   b =

                   (,
                     [1] = 4
                     [2] = 4
                     [3] = 4
                   ,)

                 }

octave:61> g(1:2).c = 3
                 g =
                 {
                   a =

                   (,
                     [1] = 4
                     [2] = [](0x0)
                     [3] = 5
                   ,)

                   b =

                   (,
                     [1] = 4
                     [2] = 4
                     [3] = 4
                   ,)

                   c =

                   (,
                     [1] = 3
                     [2] = 3
                     [3] = [](0x0)
                   ,)

                 }

So if you have an array of structures you cannot set all the whole array of a structure element to a single value unless the array element already exist...however you can set a slice of the array. I guess it is a matter of opinion and I understand that you cannot fill an array that doesn't exist, but it seems in this case octave should behave as if these indices do exist but are undef. Isn't this the current behavior? [g(3).c exist even though I assigned no value to it]

On a similar topic.  This is seems strange to me

octave:66> g.a = 4
                 g =
                 {
                   a = 4
                 }

octave:67> g(2).a = 5
                 g =
                 {
                   a =

                   (,
                     [1] = 4
                     [2] = 5
                   ,)

                 }

octave:68> g.b = "string"
error: invalid structure assignment
error: assignment to structure element failed
error: assignment failed, or no method for `struct = string'
error: evaluating assignment expression near line 68, column 5

shouldn't g.b = value do what g(:).b = value current does. That is set g(1).b = value. IMHO it should. Especially since

octave:74> g.a = 4
                 g =
                 {
                   a = 4
                 }

octave:75> g.b = "string"
                 g =
                 {
                   a = 4
                   b = string
                 }

octave:76> g(2).a = 5
                 g =
                 {
                   a =

                   (,
                     [1] = 4
                     [2] = 5
                   ,)

                   b =

                   (,
                     [1] = string
                     [2] = [](0x0)
                   ,)

                 }

In summary I think that g(:).a = value should set all currently defined indices for the array of structures g to value and g.b = value should set the first index to value and all other currently defined indices to undef. What do you all think?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]