[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
create struct array in oct-file
From: |
John W. Eaton |
Subject: |
create struct array in oct-file |
Date: |
Sat, 12 Jun 2010 11:31:32 -0400 |
On 12-Jun-2010, Andy Buckle wrote:
| My (simplified) dysfunctional attempt is below. I am sure this is
| easy, but I can't figure it out.
|
| #include "octave/oct.h"
| #include "octave/ov-struct.h"
|
| DEFUN_DLD (create_struct_array, args, nargout,
| "example of struct array") {
| octave_value_list retval;
| const int n=2;
| int i;
| Array2<Octave_map> aom(n,1);
| for (i=0; i<n; i++) {
| Octave_map om;
| om.assign("a",i);
| om.assign("b",i+1);
| aom(i,1)=om;
| }
| retval(0)=Cell(aom);
| return retval;
| }
|
| This fails to compile, with:
| create_struct_array.cpp:16: error: call of overloaded
| ‘Cell(Array2<Octave_map>&)’ is ambiguous
Octave_map already is a struct array, so there is no need to put it
inside an Array2 object. I think the following will do what you want:
#include "octave/oct.h"
#include "octave/oct-map.h"
DEFUN_DLD (create_struct_array, , ,
"example of struct array")
{
octave_idx_type n = 2;
Cell avals (n, 1);
Cell bvals (n, 1);
for (octave_idx_type i = 0; i < n; i++)
{
avals(i) = i;
bvals(i) = i+1;
}
Octave_map m;
m.assign ("a", avals);
m.assign ("b", bvals);
return octave_value (m);
}
jwe