help-octave
[Top][All Lists]
Advanced

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

oct-files: assigning to substructures? assigning to multidimensional str


From: Olaf Till
Subject: oct-files: assigning to substructures? assigning to multidimensional structures?
Date: Sat, 28 Jun 2008 17:10:22 +0200
User-agent: Mutt/1.5.13 (2006-08-11)

Taking the following structure:

octave-3.0.1:77> clear a
octave-3.0.1:78> a.b1.c1 = 1;

I thought that the following assignments:

octave-3.0.1:79> a.b2 = 1;
octave-3.0.1:80> a.b1.c2 = 1 
a =
{
  b1 =
  {
    c1 =  1
    c2 =  1
  }

  b2 =  1
}

octave-3.0.1:81> 

could be equivalently done with the following code (passing "a" as
first and "1" as second argument):

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

DEFUN_DLD (test_assign, args, , "test assign") {
  
  Octave_map st = args(0).map_value();
  octave_value tmp = args(1);

  st.assign("b2", tmp);

  st.contents("b1")(0).map_value().assign("c2", tmp);

  return octave_value (st);

}

but instead only the assignment to the top-level structure works:

octave-3.0.1:81> clear a
octave-3.0.1:82> a.b1.c1 = 1;
octave-3.0.1:83> a = test_assign (a, 1)
a =
{
  b1 =
  {
    c1 =  1
  }

  b2 =  1
}

octave-3.0.1:84> 

What am I doing wrong?

A different question is how the equivalent of

octave-3.0.1:...> some_structure.a(2).b = 1;

can be done in an oct-file (assigning to a component of a
multidimensional structure).

Olaf


reply via email to

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