help-octave
[Top][All Lists]

Re: comparison operators

 From: Douglas Eck Subject: Re: comparison operators Date: Wed, 20 Mar 2002 16:29:17 +0100 User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9) Gecko/20020310

```In fact, all you need is to ask for a([1 1 1 1 1])
and you get the first element repeated.

This can only be a bug ; and by its nature will
invalidate all simulations of random processes
which involve such a step.
```
```
This may be a bit strong. Consider this example

octave:40> a=rand(1,5);

octave:41> idx=a>0
idx =

1        1        1        1        1

octave:42> a(idx)
ans =

0.00284  0.18795  0.84289  0.56375  0.24161

octave:43>a([1 1 1 1 1])
ans =

1.0e-03  *

2.83558  2.83558  2.83558  2.83558  2.83558

As I understand it, this isn't a bug. Nor is it random.
The > operator returns a boolean vector, while "[1 1 1 1 1]" is a
regular (non-boolean) vector

octave:46> is_bool(idx)
ans = 1

octave:47> is_bool([1 1 1 1 1])
ans = 0

In any case, it's best to use find().

Ciao,
Doug

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

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```