help-octave
[Top][All Lists]
Advanced

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

Re: Lists of objects?


From: Joanna Rutkowska
Subject: Re: Lists of objects?
Date: Sun, 28 Oct 2012 14:12:23 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121016 Thunderbird/16.0.1

On 10/25/12 23:23, Sergei Steshenko wrote:








________________________________
From: Joanna Rutkowska <address@hidden>
To: address@hidden
Sent: Thursday, October 25, 2012 9:46 PM
Subject: Lists of objects?

[snip]

obj1 = xxx ()
list = {list, obj1}

obj2 = xxx ()
list = {list, obj2}

The code above unfortunately doesn't work well, because it creates nested cell 
arrays.

?
[snip]

Thanks,
joanna.
_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave




According to Jordi, I am well known for misunderstanding of cell arrays, 
structs, etc., but somehow I manage them to do what I need.

How about the following:

"octave:1> list_of_objects = {}
list_of_objects = {}(0x0)
octave:2> foo = 1
foo =  1
octave:3> list_of_objects{end + 1} = foo
list_of_objects =
{
   [1,1] =  1
}
octave:4> bar = [1 2 3]
bar =

    1   2   3

octave:5> list_of_objects{end + 1} = bar
list_of_objects =
{
   [1,1] =  1
   [1,2] =

      1   2   3

}
octave:6> doo = [4 5 6; 7 8 9]
doo =

    4   5   6
    7   8   9

octave:7> list_of_objects{end + 1} = doo
list_of_objects =
{
   [1,1] =  1
   [1,2] =

      1   2   3

   [1,3] =

      4   5   6
      7   8   9

}
octave:8> boo = "Hello"
boo = Hello
octave:9> list_of_objects{end + 1} = boo
list_of_objects =
{
   [1,1] =  1
   [1,2] =

      1   2   3

   [1,3] =

      4   5   6
      7   8   9

   [1,4] = Hello
}
octave:10> list_of_objects
list_of_objects =
{
   [1,1] =  1
   [1,2] =

      1   2   3

   [1,3] =

      4   5   6
      7   8   9

   [1,4] = Hello
}
octave:11> list_of_objects{3}
ans =

    4   5   6
    7   8   9

octave:12>

"

?


Thanks, that worked! Any idea why I couldn't use normal lists for stroing objects of the same type, as described in my original message?

Thanks,
joanna.



reply via email to

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