help-octave
[Top][All Lists]
Advanced

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

Re: Vectors of Structures in C++


From: John W. Eaton
Subject: Re: Vectors of Structures in C++
Date: Mon, 10 Apr 2006 23:08:01 -0400

On 10-Apr-2006, Bill Denney wrote:

| function retval = TranslateSBML()
|    retval.b = "B";
|    retval.c = makechildstruct();
| endfunction
| 
| function retval = GetSubstruct()
|    for i = 1:10
|      retval(i).d = i;
|    endfor
| endfunction
| 
| The jist of what I'm trying to do is that I want to be able to end up with 
| an index like
| 
| a.c(1).d
| 
| instead of
| 
| a.c{1}.d
| 
| as I currently get.

Try this:

  #include <octave/oct.h>
  #include <octave/Cell.h>
  #include <octave/oct-map.h>

  octave_value
  GetSubstruct (void)
  {
     Octave_map m;

     Cell tmp (dim_vector (10, 1));

     for (int i = 0; i < 10; i++)
       tmp(i) = i+1;

     m.assign ("d", tmp);

     return m;
  }

  DEFUN_DLD (TranslateSBML, , ,
    "TranslateSBML")
  {
     Octave_map m;

     m.assign  ("b", "B");
     m.assign ("c", GetSubstruct ());

     return octave_value (m);
  }

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]