help-octave
[Top][All Lists]
Advanced

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

Re: struct weirdness


From: Sergei Steshenko
Subject: Re: struct weirdness
Date: Thu, 23 Aug 2012 13:48:51 -0700 (PDT)


--- On Thu, 8/23/12, Przemek Klosowski <address@hidden> wrote:

> From: Przemek Klosowski <address@hidden>
> Subject: struct weirdness
> To: "address@hidden" <address@hidden>
> Date: Thursday, August 23, 2012, 7:46 AM
> I was looking at the example from http://wiki.octave.org/Cookbook:
> 
> samples = struct ("patient", {"Bob", "Kevin", "Bob" ,
> "Andrew"},
>                
>    "age",     [ 45 
> ,  52    ,  45   , 
> 23     ],
>                
>    "protein", {"H2B", "CDK2" , "CDK2",
> "Tip60" },
>                
>    "tube"   , [
> 3   ,  5     , 
> 2    ,  18     ]
>                
>    );
> 
> in Octave 3.6.2. I see that samples.patient returns the
> sequence of names, as I'd expect (ans = 'Bob, ans = Kevin,
> etc). However, samples.age returns the 'age' array four
> times. Also, samples(1)
> returns
> 
> scalar structure containing the fields:
>  patient = Bob
>      age =
> 45   52   45   23
>  protein = H2B
>     tube =  3    5   
> 2   18
> 
> rather than what I was hoping for (Bob, 45, H2B, 3).
> 
> This cookbook recipe looked like a neat idea for keeping
> track of complex data but is there a better way using
> struct() for this purpose? or is a newer version of Octave
> required?
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
> 

I think you've stumbled upon a number of bugs.

Here is my session (octave-3.6.2) - the 'foo' part is unrelated to your case, 
but it shows what I think is a bug:

"
octave:1> foo.bar = [1 2 3; 4 5 6]
foo =

  scalar structure containing the fields:

    bar =

       1   2   3
       4   5   6


octave:2> size(foo.bar)
ans =

   2   3

octave:3> samples = struct ("patient", {"Bob", "Kevin", "Bob" , "Andrew"},
>                    "age",     [ 45  ,  52    ,  45   ,  23     ],
>                    "protein", {"H2B", "CDK2" , "CDK2", "Tip60" },
>                    "tube"   , [ 3   ,  5     ,  2    ,  18     ]
>                    );
octave:4> samples.tube
ans =

    3    5    2   18

ans =

    3    5    2   18

ans =

    3    5    2   18

ans =

    3    5    2   18

octave:5> size(samples.tube)
error: Invalid call to size.  Correct usage is:

 -- Built-in Function:  size (A)
 -- Built-in Function:  size (A, DIM)


Additional help for built-in functions and operators is
available in the on-line version of the manual.  Use the command
`doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at http://www.octave.org and via the address@hidden
mailing list.
octave:5> 
".

IMO, since "size(foo.bar)" is accepted above, "size(samples.tube)" (this is 
from your case) should be accepted too, but it is not.

You may check that samples.age is equally problematic.

Regards,
  Sergei.


reply via email to

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