help-octave
[Top][All Lists]
Advanced

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

Re: warning: value not equal to 1 or 0 converted to logical 1


From: James Sherman Jr.
Subject: Re: warning: value not equal to 1 or 0 converted to logical 1
Date: Tue, 15 Nov 2016 11:26:34 -0500

On Tue, Nov 15, 2016 at 8:43 AM, babelproofreader
<address@hidden> wrote:
> This warning is produced by this code snippet:
>
> condition = ( opt_osc >= opt_osc_smooth ) ; % +1 for longs
> short_vec = ( opt_osc < opt_osc_smooth ) ; idx = find( short_vec ) ;
> condition( idx ) = -1 ; % -1 for shorts ***WARNING GIVEN ON THIS LINE***
>
> and I don't understand why. The idx vector is just an index vector to set
> the values in the condition vector at these indices to -1. opt_osc and
> opt_osc_smooth are numeric vectors of equal length with no NaN, NA or inf
> values.
>
>
>
> --
> View this message in context: 
> http://octave.1599824.n4.nabble.com/warning-value-not-equal-to-1-or-0-converted-to-logical-1-tp4680617.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-octave

When you defined your condition vector:
>> condition = ( opt_osc >= opt_osc_smooth ) ;
Octave typecasts condition as a logical vector (i.e. a vector of 0's
or 1's) since it is the output of a logical operation.
So, when you try to assign a value that is not 0 or 1 (in this case
-1), octave warns you that any nonzero value is treated as a logical
1.  So it assigns 1's where you ostensibly want -1 (since -1 doesn't
exist as a logical value).

If you want your logical vector to actually be an integer, you could
do something like:
>> condition = int8( opt_osc >= opt_osc_smooth ) ;
to convert condition into an 8-bit signed integer vector.

Hope this helps,

James Sherman



reply via email to

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