[Top][All Lists]

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

Non-integer indices in ranges

From: John W. Eaton
Subject: Non-integer indices in ranges
Date: Tue, 2 Nov 2010 14:36:41 -0400

On  2-Nov-2010, Martin, Cary wrote:

| Hello World - This issue is probably well known to the users of this
| list but if I execute this code in Octave:
| x = 0:1:10;
| x(1.5:5);
| This is received:
| error: subscript indices must be either positive integers or logicals.
| In Matlab I get:
| ans =
|      1     2     3     4
| To a certain extent the Matlab response is of course ridiculous

Even more ridiculous is what happens if you do this:

  x = [1,2,3,4,5];
  idx = 1.5:5;

Given that


"works", why shouldn't you be allowed to store the index in a variable?

| but is
| there any simple way to get this behavior in Octave or otherwise work
| around this issue? I've got some external legacy code which  seems to
| expects this behavior which I'd like to use without extensive rewriting.

The current development sources and recent 3.3.x snapshots have

  octave:1> help allow_noninteger_range_as_index 
  `allow_noninteger_range_as_index' is a built-in function

   -- Built-in Function: VAL = allow_noninteger_range_as_index ()
   -- Built-in Function: OLD_VAL = allow_noninteger_range_as_index
       Query or set the internal variable that controls whether
       non-integer ranges are allowed as indices.  This might be useful
       for MATLAB compatibility; however, it is still not entirely
       compatible because MATLAB treats the range expression differently
       in different contexts.

This feature is enabled if you start Octave with the --traditional


reply via email to

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