help-octave
[Top][All Lists]
Advanced

[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 17:28:27 -0400

On Aug 10, 2011, at 5:15 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
> 
> You have (conveniently) omitted my example with 'celldisp':
> 
> "
> octave:1> c = {"a string", rand(2, 2)}
> c =
> {
>  [1,1] = a string
>  [1,2] =
> 
>     0.245929   0.096505
>     0.018941   0.231544
> 
> }
> ...
> octave:4> celldisp(c)
> c{1} =
> 
> a string
> 
> c{2} =
> 
>   0.245929   0.096505
>   0.018941   0.231544
> 
> octave:5>   
> ".
> 
> The 'celldisp' example has just _one_ index. And I'm happy with it.
> 
> Why/what for in practice should I see _two_ indexes in 1d cell arrays ?
> 
> I.e. if I only use 'celldisp' to display cell arrays contents, what
> _practically_ important information about cell arrays am I going to lose ?

I don't think you lose any information if you just use celldisp.

Ben





reply via email to

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