Zero-One indexing a length-one vector?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Zero-One indexing a length-one vector?

Keh-Cheng Chu
Hi,

In Octave, can I use zero-one indexing on a length-one vector?
I have some functions that work correctly in MATLAB but fail
in Octave when the arguments are length-one vectors.

Here is an example:

    octave:15> b1 = [1]; b2 = [1 2]; b3 = [1 2 3];
    octave:16> b1 (b1<0), b2 (b2<0), b3 (b3<0)
    ans = [](0x0)
    ans = [](1x0)
    ans = [](1x0)
    octave:17> b2 (b2<0) = b2 (b2<0) + 1
    b2 =

      1  2

    octave:18> b1 (b1<0) = b1 (b1<0) + 1
    error: invalid  index = 0
    error: evaluating assignment expression near line 18, column 11

(The value of prefer_zero_one_indexing doesn't make any difference
here.  In MATLAB, line 18 produces "b1 = 1" without any error.)

One related (?) question that I have is this:

   Why is b1(b1<0) a [](0x0) and not a [](1x0) or a [](0x1)?  After
   all, b1 can be either a row or a column vector, so why isn't
   one of the dimensions of the empty matrix 1?

Thanks in advance for any help.


Keh-Cheng Chu
Center for Extreme Ultraviolet Astrophysics
University of California at Berkeley
[hidden email]
   

Reply | Threaded
Open this post in threaded view
|

Re: Zero-One indexing a length-one vector?

John Eaton-4
Keh-Cheng Chu <[hidden email]> wrote:

: In Octave, can I use zero-one indexing on a length-one vector?
: I have some functions that work correctly in MATLAB but fail
: in Octave when the arguments are length-one vectors.
:
: Here is an example:
:
:     octave:15> b1 = [1]; b2 = [1 2]; b3 = [1 2 3];
:     octave:16> b1 (b1<0), b2 (b2<0), b3 (b3<0)
:     ans = [](0x0)
:     ans = [](1x0)
:     ans = [](1x0)
:     octave:17> b2 (b2<0) = b2 (b2<0) + 1
:     b2 =
:
:       1  2
:
:     octave:18> b1 (b1<0) = b1 (b1<0) + 1
:     error: invalid  index = 0
:     error: evaluating assignment expression near line 18, column 11

This bug is fixed in my sources and should not appear in version
1.1.1, which I plan to release soon.

: One related (?) question that I have is this:
:
:    Why is b1(b1<0) a [](0x0) and not a [](1x0) or a [](0x1)?  After
:    all, b1 can be either a row or a column vector, so why isn't
:    one of the dimensions of the empty matrix 1?

I don't know.  I suppose `prefer_column_vectors' could be used to
determine the result.  Hmmm.

jwe