[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 10:12:25 -0500 |
On Nov 13, 2012, at 9:42 AM, Jordi Gutiérrez Hermoso wrote:
> On 13 November 2012 09:32, Ben Abbott <address@hidden> wrote:
>>
>> 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?
>>
>> 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.
>
> Consider the following:
>
> s = struct("foo", {1, "lol"}, "bar", {2, {2}})
>
> then s.foo is a cs-list with two different types, as is s.bar.
>
>> Are you looking to create a cell-array from a structure while
>> maintaining the original cell-array's size, or something else.
>
> Precisely this, I want the equivalent of
>
> reshape({s.foo}, size(s))
>
> which isn't such a mouthful. I would expect something like s("foo") to
> do this, indexing with () and strings, or s.("foo"), but the latter
> syntax is already a synonym for s.foo.
>
> The point is that I think struct arrays are best interpreted as cell
> arrays where one dimension is indexed with strings instead of
> positive integers. Indeed, the struct2cell and cell2struct functions
> perform the conversion this way, by changing the way that one
> dimension is indexed, whether with strings or positive integers. The
> problem is that there seems to be no way to index struct arrays along
> their string dimension in the same way that you can index cell arrays.
>
> So, if the language doesn't have what I want, then what's the point of
> s.foo returning cs-lists?
I'm pretty sure the cs-list behavior for structures predates the introduction
of cell-arrays in Matlab 5. Meaning I think the language evolved as a
reaction to a need, rather than a plan.
> How is this supposed to be used? It seems to
> me like the most natural use of struct arrays is to do something like
> a CSV file where the column headers turn into struct array field
> names, but if indexing by those field names gives you cs-lists, then a
> weird indirection appears in the middle.
>
> So how are struct arrays meant to be used?
Would supporting an empty index to produce an equivalent cell array be useful
...
cellarray = s.()
Where the leading dimensions of the cellarray would be equal size(foo) and an
extra dimension would be added for the fields?
Ben
- struct arrays and cs-lists, Jordi Gutiérrez Hermoso, 2012/11/12
- Re: struct arrays and cs-lists, Daniel J Sebald, 2012/11/12
- struct arrays and cs-lists, John W. Eaton, 2012/11/13
- Re: struct arrays and cs-lists, Jordi Gutiérrez Hermoso, 2012/11/13
- Re: struct arrays and cs-lists, Jordi Gutiérrez Hermoso, 2012/11/13
- Re: struct arrays and cs-lists, Ben Abbott, 2012/11/13
- Re: struct arrays and cs-lists, Jordi Gutiérrez Hermoso, 2012/11/13
- Re: struct arrays and cs-lists,
Ben Abbott <=
- Re: struct arrays and cs-lists, Benjamin Abbott, 2012/11/13
- Re: struct arrays and cs-lists, Jordi Gutiérrez Hermoso, 2012/11/13
- Re: struct arrays and cs-lists, Ben Abbott, 2012/11/13
- Re: struct arrays and cs-lists, Olaf Till, 2012/11/13
- Re: struct arrays and cs-lists, Jordi Gutiérrez Hermoso, 2012/11/13
- Re: struct arrays and cs-lists, John W. Eaton, 2012/11/13
- Re: struct arrays and cs-lists, Olaf Till, 2012/11/13
- Re: struct arrays and cs-lists, Olaf Till, 2012/11/13
- Re: struct arrays and cs-lists, Jordi Gutiérrez Hermoso, 2012/11/13
Re: struct arrays and cs-lists, Ben Abbott, 2012/11/13