help-octave
[Top][All Lists]
Advanced

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

Re: struct weirdness


From: Jordi Gutiérrez Hermoso
Subject: Re: struct weirdness
Date: Thu, 23 Aug 2012 17:11:03 -0400

On 23 August 2012 17:06, Sergei Steshenko <address@hidden> wrote:
> --- On Thu, 8/23/12, Jordi Gutiérrez Hermoso <address@hidden> wrote:
>> Klosowski <address@hidden> wrote:

>> > 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     ]
>> >
>>     );
>>
>> This the square brackets should be curly. Then it's a struct array,
>> and if you do samples(1) and samples(2), you get the data you
>> expect. Can you update the wiki?
>>
>> I find it difficult to think in terms of cell arrays. They are
>> basically multidimensional cell arrays, which are already weird in
>> themselves since indexing them with {} gives cs-lists, except the
>> one dimension is indexed strings instead of positive integers.
>>
>>
>
> "This the square brackets should be curly" - if it's a must, and
> square brackets are accepted, then we have a bug - because no error
> message is issued.

No, read the struct docstring. It's a should, not a must. When the
brackets are square, it's treated as a singleton "cell" and gets
broadcast along the other dimensions of the struct array. It's really
another case of broadcasting.

-  Jordi G. H.


reply via email to

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