octave-maintainers
[Top][All Lists]
Advanced

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

Re: struct arrays and cs-lists


From: Ben Abbott
Subject: Re: struct arrays and cs-lists
Date: Tue, 13 Nov 2012 09:32:19 -0500

On Nov 13, 2012, at 8:06 AM, Jordi Gutiérrez Hermoso wrote:

> On 13 November 2012 08:05, Jordi Gutiérrez Hermoso <address@hidden> wrote:
>> On 13 November 2012 00:02, John W. Eaton <address@hidden> wrote:
>>> On 12-Nov-2012, Jordi Gutiérrez Hermoso wrote:
>>> 
>>> | I don't really understand why if s is a struct array with field foo,
>>> | then "s.foo" is a cs-list. What's the purpose of this? How can you get
>>> | something like a cell array instead without something as roundabout as
>>> | resize(size(s), {s.foo})? Does it have to be this way, is there
>>> | something else we can do instead?
>>> 
>>> I don't see that we can do anything else if we want to preserve Matlab
>>> compatibility.
>> 
>> Sure, we can't change it, but how is it supposed to be used? Why is it
>> like this at all? There must *some* method to the Madlab.
> 
> By way of contrast, for cell arrays you can avoid cs-lists and get
> subcells if you index with () instead of {}. Why is there nothing
> equivalent for struct arrays?
> 
> - Jordi G. H.

For cells indexing with () preserves the cell class just as it does for any 
data type (including structures).  That's equivalent correct?  ... So, its not 
clear to me what you want to do.  Are you looking to create a cell-array from a 
structure while maintaining the original cell-array's size, or something else.

Maybe you are referring to the feature that a cs-list created from a structure 
using (:) or a cell-array using {:} is a row vector but indexing as (:) creates 
a column vector?

        a = {1, 2, 3};
        size ([a(:)])
        ans =   3   1
        size ({a{:}})
        ans =   1   3

        [a(1:3).foo] = deal (1, 2, 3);
        a = a(:)
        size (a)
        ans =   3   1
        size ([a.foo])
        ans =   1   3
        size ([a(:).foo])
        ans =   1   3

Ben




reply via email to

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