help-octave
[Top][All Lists]
Advanced

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

need help understanding structure arrays


From: DushanM
Subject: need help understanding structure arrays
Date: Thu, 18 Oct 2007 20:44:15 -0600
User-agent: MacSOUP/2.8.1 (Mac OS X version 10.4.10 (x86))

For the last few days I've been trying to learn how to use struc-
ture arrays, but keep getting confused by octave responses I don't
understand.  First I'll describe what I'm interested in doing, then what
I tried, and octave's responses (using 2.9.15).

There will be a 1- or 2-D array of surface patches (on the order of
100), with each of which I want to associate a vector position, a
scalar area, a vector normal, and a vector current. So if the array
is a simple sequence (a 1-D index) going from n=1 to 100, I'd like
to create the structure array

    src(n).pos  =  [p1,p2,p3]
    src(n).area =  scalararea
    src(n).nrml =  [o1,o2,o3]
    src(n).curr =  [j1,j2,j3]

If there's no index 'n' - for one surface patch - this works just
as the octave manual says it should using 'struct'.  But whenever
I try to introduce an index before the '.', octave complains.

So I went back to square 1 and tried out the first example in the
manual's section '6.1.1  Structure Arrays', bottom of p.65.  Here's
the result of typing in the first of the example's lines:

----------- begin snippet ----------
  *** octave-2.9.15:46$
  => x(1).a = "string1" 
  error: in indexed assignment of matrix, last lhs index must be ()
  error: assignment failed, or no method for `matrix = string'
  error: evaluating assignment expression near line 46, column 8
------------ end snippet -----------

Would someone please shed some light on what is going on here, and
what I'm doing wrong?  The discussions I found on the Internet
helped, but did not resolve my problem.

Thanks.

- Dushan Mitrovich

PS, FWIW, I found the documentation hard to follow, because the
explanations do not always build on previous explanations.  They
assume pieces of knowledge that a beginner at octave/matlab does
not yet have.  Some of the examples show the fancy stuff you can
do, but are just confusing if the reader doesn't understand the
basics of the particular topic.  An admission: I did not read the
manual from cover to cover and memorize all the details.  I read
the parts I needed to learn, refering back and forth in the manual
as required.


reply via email to

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