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:46:43 +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

One addtion to my previous mail.  If I have a cell array of matrices,
like 

s = cell(5);
for i=1:5; j=1:5
  s(i,j) = NA(100,1);
endfor; endfor

What is the clean/preferred way of setting elements inside an array?
For example, I want to set even-indexed elements of the first array to
5.  This one works:

s{1,1}(2:2:100) = 5;

But this looks like a trick to me.  Maybe using cellindexmat?  A simpler
way? 

-- 
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]