help-octave
[Top][All Lists]
Advanced

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

Zero-One indexing a length-one vector?


From: Keh-Cheng Chu
Subject: Zero-One indexing a length-one vector?
Date: Mon, 30 Jan 1995 14:59:02 -0800

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
address@hidden
   


reply via email to

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