help-octave
[Top][All Lists]
Advanced

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

Re: cell{1:5}=1 not working for me!!!


From: Francesco Potortì
Subject: Re: cell{1:5}=1 not working for me!!!
Date: Fri, 01 Jun 2012 15:36:38 +0200

>>>The first fact is easy to understand: you can assign to a cell with
>>>any of the operators () or {}.
>>
>> Is there an historical reason to this, I suppose, or more simply a
>> Matlab compatibility reason.  I find this ambiguity confusing.  Is there
>> a recommended style?
>
>What exactly is the ambiguity with () and {}? They're different things.
>
>Indexing with {} gives you cs-lists, possibly with only one element.
>Indexing with you () gives you subcells. You can always assign a
>subcell of compatible size to a subcell, but you can only assign to
>cs-lists as long as they are one-element.
>
>If you think the following needs to be better written, please let me
>know, and we can reword it:
>
>    
> http://www.gnu.org/software/octave/doc/interpreter/Indexing-Cell-Arrays.html

Thanks for the tip.  Yes, I have read that page many times (and I have
implemented cose using it), but the problem is, I use cells very
sparingly, so I keep forgetting because I find the concept unintuitive.
Anyway, an observation:

In that page, thre are two examples of using {} on the left side of an
assignment.  One uses deal on the right side.  Here one could add a
note that in the special case of the cs-list being composed of a single
element the syntax can be simpler and how in that special case is
different from using ().

The other example is

 x{1, :} = []

but it is not clear to me why this one works.  While for example

octave> c{1, :} = {8}
error: invalid assignment to cs-list outside multiple assignment


-- 
Francesco Potortì (ricercatore)        Voice:  +39.050.315.3058 (op.2111)
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Fax:    +39.050.315.2040  
(entrance 20, 1st floor, room C71)     Web:    http://fly.isti.cnr.it


reply via email to

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