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: Sun, 2 Sep 2012 11:35:00 -0400

On 1 September 2012 19:54, Sergei Steshenko <address@hidden> wrote:
>     26  samples = consistent_struct\
>     27              (
>     28              "patient", {"Bob", "Kevin", "Bob" , "Andrew"},
>     29              "age",     [ 45  ,  52    ,  45   ,  23     ],
>     30              "protein", {"H2B", "CDK2" , "CDK2", "Tip60" },
>     31              "tube"   , [ 3   ,  5     ,  2    ,  18     ]
>     32              );

Btw, since you don't seem to understand how struct is optimised for
the array case (since, y'know, Octave is an array-oriented language),
the scalar struct you want to create can be created with struct like
so:

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

The part you don't understand is that the cell arguments of struct are
turned into dimensions of the resulting struct array. When there is no
cell argument (e.g. when it's an ordinary array instead of a cell),
it's treated as a single element of a cell array. If you want to have
cells inside the resulting struct, you have to nest them inside
another cell, by doubling up the curly braces. The struct function is
intended for struct arrays, but you hate struct arrays because you get
confused when they give you cs-lists because you don't understand
cs-lists, because you don't understand how cs-lists work inside other
functions such as the size() function.

Thank you for your guidance, however. Your efforts continue to improve
Octave every day.

- Jordi G. H.


reply via email to

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