Subtle nested structure assignment behavior

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Subtle nested structure assignment behavior

Daniel Sebald
Octave doesn't allow assigning a value to a structure array element if the levels get too deep.  Is this a bug?  For example:

octave:11> sroot(1).one.two.three = 55
sroot =
{
  one =
  {
    two =
    {
      three: 1x1 scalar
    }

  }

}

octave:12> sroot(2).one.two.three = 66
error: invalid vector index = 2
error: evaluating assignment expression near line 12, column 24


Sometimes I'm seeing this error:

error: scalar cannot be indexed with .
error: evaluating assignment expression near line 9, column 23


However, there is a work-around in the following way:

octave:17> one.two.three = 68;
octave:18> sroot(2).one = one
sroot =
{
  one =

  (,
    [1] =
    {
      two =
      {
        three: 1x1 scalar
      }

    }

    [2] =
    {
      two =
      {
        three: 1x1 scalar
      }

    }

  ,)

}


Dan
Reply | Threaded
Open this post in threaded view
|

Subtle nested structure assignment behavior

John W. Eaton
Administrator
On 24-Dec-2008, Daniel J Sebald wrote:

| Octave doesn't allow assigning a value to a structure array element
| if the levels get too deep.  Is this a bug?  For example:
|
| octave:11> sroot(1).one.two.three = 55
| sroot =
| {
|   one =
|   {
|     two =
|     {
|       three: 1x1 scalar
|     }
|
|   }
|
| }
|
| octave:12> sroot(2).one.two.three = 66
| error: invalid vector index = 2
| error: evaluating assignment expression near line 12, column 24

Using a copy of Octave built from the current sources, I see

  octave:1>   x(1).a.b.c = 1;
  octave:2>   x(2).a.b.c = 2;
  error: matrix cannot be indexed with .

which also does not look right, but is not the same error as you
show.  So what version of Octave are you using?

jwe
Reply | Threaded
Open this post in threaded view
|

Re: Subtle nested structure assignment behavior

Daniel Sebald
John W. Eaton wrote:

> On 24-Dec-2008, Daniel J Sebald wrote:
>
> | Octave doesn't allow assigning a value to a structure array element
> | if the levels get too deep.  Is this a bug?  For example:
> |
> | octave:11> sroot(1).one.two.three = 55
> | sroot =
> | {
> |   one =
> |   {
> |     two =
> |     {
> |       three: 1x1 scalar
> |     }
> |
> |   }
> |
> | }
> |
> | octave:12> sroot(2).one.two.three = 66
> | error: invalid vector index = 2
> | error: evaluating assignment expression near line 12, column 24
>
> Using a copy of Octave built from the current sources, I see
>
>   octave:1>   x(1).a.b.c = 1;
>   octave:2>   x(2).a.b.c = 2;
>   error: matrix cannot be indexed with .
>
> which also does not look right, but is not the same error as you
> show.  So what version of Octave are you using?

The version I used to generate those error messages was 3.0.0+.  However, I'm seeing very similar messages with the latest HG version on a different machine.  There seems to be one of these errors:

error: matrix cannot be indexed with .
error: scalar cannot be indexed with .
error: invalid vector index = 2

but I can't figure out repeatable conditions where one happens versus the other.

Dan