help-octave
[Top][All Lists]

Re: Index expressions: .* vs &

 From: Jaroslav Hajek Subject: Re: Index expressions: .* vs & Date: Fri, 6 Aug 2010 14:14:49 +0200

```On Fri, Aug 6, 2010 at 10:43 AM, Mike B. <address@hidden> wrote:
> Thanks Carlo.
>
> I wasn't aware there is a difference. Thought that octave treated a real-type
> zero as a boolean.
>

No, that wouldn't work, it would be ambiguous. Think of X(ones (1,
10)) vs. X(true (1, 10)). Data class is significant, there are just
lots of automatic conversions.

>
> --- 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.
>>
>>
>>
>
>
>
> _______________________________________________
> Help-octave mailing list
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>

--
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

```