[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: arrays (matrices) of structures.
From: |
Paul Kienzle |
Subject: |
Re: arrays (matrices) of structures. |
Date: |
Thu, 18 Oct 2001 08:53:15 -0400 |
Octave does not handle arrays of structures.
You could implement it as a list of structures, using something like:
b = list
g.a = 1
g.c = 2
b(1) = g
g.a = 2
g.c = 4
b(2) = g
To access the individual elements, e.g., b(2).a, use
nth(b,2).a
To update an individual element, e.g., b(2).a = 3, use
g=b(2); g.a = 3; b(2) = g;
To get a slice along a particular field dimension, e.g., y = { b(1:2).a }, use
y = list;
for i=1:length(idx), y(i) = nth(b,2).a(i); end
To get at the elements of the slice, e.g., y{2}, use
nth(y,2)
And so on.
Paul Kienzle
address@hidden
Gabe Foster wrote:
> Hello,
>
> I'm porting some code from matlab to octave. I'm not very familier
> with
> either package, so please pardon my ignorance. I'll try to keep this short.
>
> The code I'm porting uses arrays of data structures. It has lines
> like:
> b(1).a = 1.0
> b(1).c = 2.0
> b(2).a = 3.0
> b(2).c = 4.0
>
> etc.
>
> Octave 2.0.16 gives a parse error when trying to parse these lines.
> Is this
> because it does not support arrays (or matrices) of structures?
>
> Octave 2.1.34 seems to be ok with that syntax, but does not seem to
> have a
> path variable:
>
> octave:1> path(path,"/home/gabe/octlib")
> error: `path' undefined near line 1 column 1
> error: evaluating index expression near line 1, column 1
>
> Any help would be appreciated.
>
> Thank you for you time...
>
> --> Gabe
> --
> * J. Gabriel Foster "We have advanced to new and surprising
> * Silicon Grail levels of bafflement" - Lois McMaster Bujold
> * address@hidden
>
> -------------------------------------------------------------
> 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
> -------------------------------------------------------------
-------------------------------------------------------------
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
-------------------------------------------------------------