help-octave
[Top][All Lists]
Advanced

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

Re: trouble indexing cell array


From: Jordi Gutiérrez Hermoso
Subject: Re: trouble indexing cell array
Date: Mon, 5 Nov 2012 09:47:18 -0500

On 4 November 2012 19:04, Tim Meehan <address@hidden> wrote:
> I'm having a strange problem shown below. I want to take a subset of a cell
> array and save it as a new variable. I can index the subset just fine, but
> when I try to save the subset into a new variable, it saves as only one
> element in the array. I'm mystified, can anyone tell me what I'm doing
> wrong?

The problem is you're running into comma-separates lists (cs-lists).
It's a weird Matlabism that we have to copy in Octave. Basically, the
issue is that in many cases

    c{1:3}

is syntactically equivalent to

    c{1}, c{2}, c{3}

So if you type

    a = c{1:3}

it's like typing

    a = c{1}, c{2}, c{3}

If you index a cell array with () instead of {}, you get another
subcell array instead of a cs-list:

    a = c(1:3) ## Does what you want.

There are other ways in which you can get cs-lists such as in struct
arrays, and they do have some confusing semantics.

- Jordi G. H.


reply via email to

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