[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

`size' and trailing singleton dimensions

From: Peter J. Acklam
Subject: `size' and trailing singleton dimensions
Date: 31 May 2004 16:20:19 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

I use N-dimensional array manipulation heavily in MATLAB, but
switching to Octave I run into many problems.  Trying to
understand this from the ground up, I have a few questions:

Why does Octave treat trailing singleton dimensions differently
than MATLAB, even when the `--traditional' switch is used?

It seems that trailing singleton dimensions matter in some cases,
but not in others.  For instance, `size' does care about them, but
`ndims' doesn't:

   >> x = rand(5, 7);
   >> size(x, 2)
   ans = 7
   >> size(x, 3)
   error: size: requested dimension (= 3) out of range

For the above call to `size' to work, I would have to include a
trailing singleton dimension:

   >> x = rand(5, 7, 1);
   >> size(x, 3)
   ans = 1

So `size' does not behave like MATLAB's `size'.  It also returns
singleton dimensions when called with one argument:

   >> size(x)
   ans =

           5        7        1

However, `ndims' ignores the trailing singleton dimensions:

   >> ndims(x)
   ans = 2

As a consequence `ndims(x)' isn't necessarily equal to
`length(size(x))' which it always is in MATLAB.

It seems inconsistent to me that `size' does care about trailing
singleton dimensions, but `ndims' doesn't.  What's the logic
behind this?  (I have read section 3, Data Types, but that doesn't
mention this.)


Peter J. Acklam - address@hidden -

Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

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