help-octave
[Top][All Lists]
Advanced

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

Re: struct weirdness


From: Carnë Draug
Subject: Re: struct weirdness
Date: Thu, 23 Aug 2012 23:47:24 +0100

On 23 August 2012 23:33, Przemek Klosowski <address@hidden> wrote:
> On 08/23/2012 05:10 PM, Carnė Draug wrote:
>>
>> On 23 August 2012 22:06, Sergei Steshenko <address@hidden> wrote:
>>>
>>> "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.
>>
>>
>> The should here in that sentence mean "should be curly for the example
>> to work". struct accepts others things and the behaviour seen is
>> documented and expected. It was my mistake when writing that entry for
>> the wiki. It is now fixed.
>>
>> Carnė
>>
> Great, but I still don't get your discussion of the structure access. All
> these three expressions:
>
> [samples.age]
> [samples(:).age]
> reshape ([samples(:).age], size (samples))
>
> result in the same output:
>
> ans =
>
>    45   52   45   23
>
> and the first one is simplest and most direct so it should be preferred, no?

Yes and no. The first entry is less code, but I think it makes less
obvious that we are accessing values from a structure array instead of
just a scalar structure structure.

The reason for the use of reshape is explained on the text, to
preserve the shape of the structure array: In the problem given
example it's not a problem, because it's just one vector but that may
not always be case. I guess I could move it to the discussion section
but I think it's still a more correct solution.

Carnë


reply via email to

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