From help-octave-request at bevo dot che dot wisc dot edu Sun Jan 11 21:44:37 2004 Subject: Re: Data Structure Question From: "Henry F. Mollet" To: Paul Kienzle CC: Octave_post Date: Sun, 11 Jan 2004 19:40:34 -0800 Thanks. I used a comma instead of a semi-colon because I was hoping to get a row-vector for my variable names. Then I've tried your suggestion of using a cell structure instead of a data structure (if this is the correct terminology) and had difficulties with referencing my row comments and variable names (see below with comments). Henry octave:48> mySpreadSheet mySpreadSheet = { [1,1] = 1.0000 1.1000 2.1000 3.1000 2.0000 1.2000 2.2000 3.2000 3.0000 1.3000 2.3000 3.3000 4.0000 1.4000 2.4000 3.4000 [1,2] = male fem male female [1,3] = Var1 Var2 Var3 Var4 } octave:49> iscell (mySpreadSheet) ans = 1 % OK octave:51> mySpreadSheet{1}(1,3) ans = 2.1000 %OK third value in first row octave:52> mySpreadSheet{2}(1) error: single index only valid for row or column vector % looks like a col-vector to me? octave:52> mySpreadSheet{2}(1,1) ans = m % first letter of male but I was hoping to get "male" % Does it imply that I can index with only one letter % If so, I might as well index with a number using an % additional col in my matrix? octave:53> mySpreadSheet{3}(1) error: single index only valid for row or column vector % as above for row index octave:53> mySpreadSheet{3}(1,1) ans = V % as above for row index on 1/10/04 1:08 PM, Paul Kienzle at pkienzle at users dot sf dot net wrote: > You have a ';' in comment and a ',' varname which is why it doesn't work > like you expect. You will be better off using {} rather than [] for an > array > of strings because you can then use x.comment{i} rather than > deblank(x.comment(i,:)) to reference them. You need the deblank > for [] because a character matrix must be rectangular. You don't > need it for {} because a vector of values can contain character vectors > of different lengths. > > Paul Kienzle > pkienzle at users dot sf dot net > > On Jan 10, 2004, at 1:27 PM, Henry F. Mollet wrote: > >> Am I on the right track here for the use of a data structure? I'd like >> to >> add variable names (columns) and comments (rows) to a matrix a. It >> seems to >> work for the comments but not the varnames. >> Henry >> >> >> octave:13> x.a = [1,2;3,4]; >> octave:14> x.comment = ["FirstRowComment"; "SecondRowComment"]; >> octave:15> x.varname = ["Var1", "Var2"]; >> octave:16> x >> x = >> { >> a = >> >> 1 2 >> 3 4 >> >> comment = >> >> FirstRowComment >> SecondRowComment >> >> varname = Var1Var2 >> } >> >> >> >> ------------------------------------------------------------- >> 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 -------------------------------------------------------------