[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: difference of cell arrays behavior between octave-3.0.5 and octave-3
From: |
Ben Abbott |
Subject: |
Re: difference of cell arrays behavior between octave-3.0.5 and octave-3.4.2 |
Date: |
Mon, 01 Aug 2011 12:50:40 -0400 |
On Aug 1, 2011, at 12:07 PM, Sergei Steshenko wrote:
> --- On Mon, 8/1/11, Ben Abbott <address@hidden> wrote:
>
>> From: Ben Abbott <address@hidden>
>> Subject: Re: difference of cell arrays behavior between octave-3.0.5 and
>> octave-3.4.2
>> To: "Sergei Steshenko" <address@hidden>
>> Cc: address@hidden
>> Date: Monday, August 1, 2011, 5:07 AM
>>
>> On Aug 1, 2011, at 5:31 AM, Sergei Steshenko wrote:
>>
>>> In octave-3.0.5 I have:
>>>
>>> "
>>> octave:1> foo{1}(:) = []
>>> foo =
>>>
>>> {
>>> [1,1] = [](0x0)
>>> }
>>>
>>> octave:2> foo{2}(:) = [2;3]
>>> foo =
>>>
>>> {
>>> [1,1] = [](0x0)
>>> [1,2] =
>>>
>>> 2 3
>>>
>>> }
>>>
>>> octave:3>
>>> ".
>>>
>>> In octave-3.4.2 I have:
>>>
>>> "
>>> foo{1}(:) = []
>>> foo =
>>> {
>>> [1,1] = [](0x0)
>>> }
>>> octave:2> foo{2}(:) = [2;3]
>>> error: A(I) = X: X must have the same size as I
>>> octave:2>
>>> ".
>>>
>>>
>>> Why is it so that in octave-3.4.2 I have an error ?
>>>
>>> Why at all size checking kicks in - "foo{2}(:)"
>> doesn't yet have size,
>>> it should be created according to RHS.
>>>
>>> Which of the two behaviors is nominally correct
>> (Matlab) ?
>>
>>>> clear all
>>>> foo{1}(:) = []
>>
>> foo =
>>
>> {[]}
>>
>>>> foo{2}(:) = [2;3]
>> ??? In an assignment A(:) = B, the number of
>> elements in A and B
>> must be the same.
>>
>>>> foo{2}(1:2) = [2;3]
>>
>> foo =
>>
>> [] [1x2 double]
>>
>> I compared with the developers sources (default branch) and
>> see that his last command works there as well.
>>
>> Ben
>>
>>
>>
>
> So, do I understand correctly - your screen session is from Matlab and
> it doesn't accept
>
> foo{2}(:) = [2;3]
>
> like I experienced ?
Yes. ML did not accept that syntax.
> octave:1> foo{1}(:) = []
> foo =
> {
> [1,1] = [](0x0)
> }
> octave:2> foo{2}(:) = [2;3]
> error: A(I) = X: X must have the same size as I
> octave:2>
> ".
>
> So, a practical question - how do I achieve what I want ? Isn't cell array
> supposed to hold values of possibly different sizes per index ?
>
> Thanks,
> Sergei.
The error isn't actually related to cells. For example, ...
a(:) = [1;2];
error: A(I) = X: X must have the same size as I
The syntax that works is just ...
a = [1;2];
For you cell, you can just write ...
foo{2} = [2;3];
Ben