help-octave
[Top][All Lists]

## Re: Index expressions: .* vs &

 From: Mike B. Subject: Re: Index expressions: .* vs & Date: Fri, 6 Aug 2010 01:43:33 -0700 (PDT)

```Thanks Carlo.

I wasn't aware there is a difference. Thought that octave treated a real-type
zero as a boolean.

--- On Fri, 6/8/10, c. <address@hidden> wrote:

> Subject: Re: Index expressions: .* vs &
> Cc: "Octave mai. lis." <address@hidden>
> Date: Friday, 6 August, 2010, 5:03 PM
>
> On 6 Aug 2010, at 07:55, Mike B. wrote:
>
> > Hi All,
> >
> > Can someone please explain the following behaviour:
> >
> > a = [1; 2 ];
> > z1 = (a > 0)&(a>1);
> > z2( z1 ) = 1
> >
> > gives z2 = [ 0, 1 ] (as expected).
> >
> > Now,
> > z1 = (a > 0).*(a>1);
> > z2( z1 ) = 1
> >
> > gives
> >> error: subscript indices must be either positive
> integers or logicals.
> >
> > why the difference between & and .* when used for
> index expressions?
> >
> > Thanks,
> > Mike.
>
> That is because:
>
> --------------------
> >> a = [1; 2 ];
> >> z1 = (a > 0).*(a>1);
> >> class (z1)
> ans = double
> --------------------
>
> while
>
> --------------------
> >> z1 = (a > 0) & (a>1);
> >> class (z1)
> ans = logical
> --------------------
>
> HTH,
> c.
>
>
>

```