From help-octave-request at bevo dot che dot wisc dot edu Tue Jan 15 03:32:25 2002 Subject: RE: Arrays of structures question From: (Ted Harding) To: Abe Taha Cc: help-octave at bevo dot che dot wisc dot edu Date: Tue, 15 Jan 2002 08:22:45 -0000 (GMT) On 15-Jan-02 Abe Taha wrote: > I am new to octave and am having a slight problem running an old Matlab > code. The offending lines are > > for i=1:nBC > nodeNum = nodebcs(i).num; > end; > > where nodebcs is a vector of structs, each having num, x, and y as > members. When I run the code, Octave prints out > can't perform indexing operation for struct type It looks as though any attempt to create an "array of structs" ignores the indexing: octave:1> X(1).num = 1; octave:2> X(1).text="number 1" X.text = number 1 octave:3> X(2).num=2; octave:4> X(2).text="number 2" X.text = number 2 octave:5> whos *** local user variables: prot type rows cols name ==== ==== ==== ==== ==== rwd struct - - X octave:6> X X = { num = 2 text = number 2 } Hence any subsequent attempt to refer to an indexed struct will fail: octave:7> X(2) error: can't perform indexing operations for struct type (and I guess Abe Taha's confusion arises from the fact that there is no error message when the structure is created). Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) Fax-to-email: +44 (0)870 167 1972 Date: 15-Jan-02 Time: 08:22:45 ------------------------------ XFMail ------------------------------ ------------------------------------------------------------- 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 -------------------------------------------------------------