help-octave
[Top][All Lists]
Advanced

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

Re: Index expressions: .* vs &


From: c.
Subject: Re: Index expressions: .* vs &
Date: Fri, 6 Aug 2010 09:03:01 +0200


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.




reply via email to

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