From octave-maintainers-request at bevo dot che dot wisc dot edu Tue May 14 22:29:23 2002 Subject: cell arrays and structure arrays From: "John W. Eaton" To: octave-maintainers mailing list Date: Tue, 14 May 2002 22:28:47 -0500 I've just checked in some changes to the Octave CVS archive that make cell arrays and structure arrays work. This includes a significant set of changes to the code that handles indexing and indexed assignment of values. There will be some incompatibilities for existing user-defined data types. I realize that this may cause some trouble, but I think the new way is much better than the old and justifies the backwardly incompatible change. I also don't think there are very many user-defined data types out there, and I'm willing to provide some help with conversions. Here is a sample of what is now possible (x previously undefined): octave:1> X{2,2}.foo(2).bar(2:3,2:3) = rand (2) x = { [1,1] = [](0x0) [2,1] = [](0x0) [1,2] = [](0x0) [2,2] = { foo = { bar = ( [1] = [](0x0) [2] = 0.00000 0.00000 0.00000 0.00000 0.86394 0.22945 0.00000 0.51638 0.37879 ) } } } In the above, X is a 2x2 cell array, FOO is a 2-element structure array with one key, BAR, a 3x3 matrix. Here is what happens after you add another element (BAZ) to the structure array: octave:3> x{2,2}.foo(1).baz = "I am one BAZ"; octave:4> x{2,2}.foo(2).baz = "I am too BAZ"; octave:5> x x = { [1,1] = [](0x0) [2,1] = [](0x0) [1,2] = [](0x0) [2,2] = { foo = { baz = ( [1] = I am one BAZ [2] = I am too BAZ ) bar = ( [1] = [](0x0) [2] = 0.00000 0.00000 0.00000 0.00000 0.86394 0.22945 0.00000 0.51638 0.37879 ) } } } With these new types, you can create some really complex data structures. But more importantly, both are supposed to be Matlab compatible, so people who want it can provide much more Matlab functionality than in the past. I think simple structures are still backwardly compatible with previous versions of Octave. Some things that still need to be done: * Cell arrays should really be N-dimensional. * Given a cell, X, Expressions like X{:} should return a "comma separated list" object that can be passed in to a function as a series of disticnt arguments, one per list item. Currently Octave produces an Octave list value, which does not have this special property (if you pass it to a function, the function sees a single list paramter). * Save and load need to be fixed to handle structure arrays and cells. * The [ ] operator needs to be fixed so that it can be used to concatentate cell arrays as well as numeric and character arrays. * ? Comments? Thanks, jwe