help-octave
[Top][All Lists]
Advanced

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

Re: Octave_map and vectors


From: John W. Eaton
Subject: Re: Octave_map and vectors
Date: Thu, 30 Oct 2003 11:05:40 -0600

On 30-Oct-2003, Claudio Belotti <address@hidden> wrote:

| Geraint & John
|       I've managed to do what I want (returning a list of maps), so now the 
output is:
| 
| ans =
| (
|   [1] =
|   {
|     name = Hello
|     number = 1
|   }
|  
|   [2] =
|   {
|     name = world
|     number = 2
|   }
|  
| )

Why not use Octave_map to generate a structure array?  The Octave
"list" type is obsolete and probably shouldn't be used in new code.
If you really want to return a collection of scalar structures, then
you should use cell arrays, not lists.

It is also less efficient to return a collection of scalar structures
than to create a structure array.  A structure array contains only one
copy of each field name.  The way you have done it, there is one copy
for each element

|   Octave_map map1,map2;
|   map1["name"]=(octave_value)"Hello";
|   map2["name"]=(octave_value)"world";
|   map1["number"]=(octave_value)1;
|   map2["number"]=(octave_value)2;

Casting may work here, but it is definitely bad style.  You should write

   map1["name"] = octave_value ("Hello");
   map2["name"] = octave_value ("world");
   map1["number"] = octave_value (1);
   map2["number"] = octave_value (2);

Are you using an old version of Octave?  I would expect to see

  map1["name"](0) = octave_value ("Hello");

these days, because the elements of Octave_map are now Cells, not just
octave_values or lists.  In the CVS sources, they are N-d Cells, but I
think the interface is backwardly compatible.

I would recommend upgrading to 2.1.50.

If you would like N-d arrays, you can try the current CVS sources, or
you can wait a bit and try 2.1.51 (but unless you really need N-d
arrays, I would stick with 2.1.50 for now).

jwe



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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