[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: why two indexes in 1d cell array ? (octave-3.4.2) ... how about more
From: |
Ben Abbott |
Subject: |
Re: why two indexes in 1d cell array ? (octave-3.4.2) ... how about more dimensions ? |
Date: |
Wed, 10 Aug 2011 18:22:18 -0400 |
On Aug 10, 2011, at 5:33 PM, Sergei Steshenko wrote:
> --- On Wed, 8/10/11, Ben Abbott <address@hidden> wrote:
>
>> From: Ben Abbott <address@hidden>
>> Subject: Re: why two indexes in 1d cell array ? (octave-3.4.2) ... how about
>> more dimensions ?
>> To: "Sergei Steshenko" <address@hidden>
>> Cc: address@hidden
>> Date: Wednesday, August 10, 2011, 2:06 PM
>> On Aug 10, 2011, at 3:18 PM, Sergei
>> Steshenko wrote:
>>
>>> c =
>>> {
>>> [1,1] = a string
>>> [1,2] =
>>> "
>>>
>>> I see _two_ indexes, i.e. "[1,1]...", "[1,2]", though
>> to me it looks like
>>> created a _1d_ (just _one_ dimension) cell array;
>>
>> Matlab originated from Fortran code. Thus, arrays were/are
>> column-major.
>>
>> http://en.wikipedia.org/wiki/Row-major_order#Column-major_order
>>
>> When the source code switched to C, Matlab maintained the
>> default column-major storage order for arrays. This means
>> that A = 1:5 produces a single row with 5 columns.
>>
>> However, since C is row-major ...
>>
>> http://en.wikipedia.org/wiki/Row-major_order#Row-major_order
>>
>> ... a 1D array requires two indices. The fist specifies the
>> row [1], and the second the column.
>>
>> For compatibility with Matlab, Octave adopted the same
>> approach.
>>
>>> Is this all expected and documented behavior ?
>>
>> Yes this is expected and deliberate. If you search the
>> manual. you'll find a few instances where the effect of
>> "column-major" ordering is mentioned.
>>
>> Ben
>
> Let's again have a look at documentation:
>
> http://www.gnu.org/software/octave/doc/interpreter/Basic-Usage-of-Cell-Arrays.html#Basic-Usage-of-Cell-Arrays
> .
>
> I am going to repeat actions described in the documentation:
>
> 1a) documentation:
> c = {"a string", rand(2, 2)};
>
> 1b) me:
> "
> c = {"a string", rand(2, 2)}
> c =
> {
> [1,1] = a string
> [1,2] =
>
> 0.64730 0.79055
> 0.40904 0.54691
>
> }
> "
> - 'octave' prints differently, but I didn't put ';' at the end of my input,
> so IMO in this case 'octave' behaves as expected;
>
>
> 2a) documentation:
> "
> c{1:2}
> ⇒ ans =
>
> (,
> [1] = a string
> [2] =
>
> 0.593993 0.627732
> 0.377037 0.033643
>
> ,)
> "
> 2b) me:
> "
> c{1:2}
> ans = a string
> ans =
>
> 0.64730 0.79055
> 0.40904 0.54691
> ".
>
> In '2b)' _no_ indexes.
>
> Why the discrepancy between actual behavior and the documentation ?
>
> Thanks,
> Sergei.
You've found an error in the documentation.
If someone doesn't get to is before me, I'll submit a fix for it later today.
Ben