[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:06:51 -0400 |
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