Comparison Operators

When doing a comparison in Octave you apply a comparison operator on two numbers and the result is either true or false, represented by 1 or 0.

operation

arithmetic operations

logical operations

comparisons

operators

+ - * / ^

&& || !

> >= < <= == !=

operands

numbers

logical values

numbers

result

a number

a logical value

a logical value

The comparison operators are:

>

>=

<

<=

==

!=

greater than, >

greater than or equal to,

less than, <

less than or equal to,

equal to, =

not equal to,

>>> a=1; b=2; c=2; d=3;
>>> a>=b
ans = 0
>>> b>=c
ans = 1
>>> (a < b) && (c!=d)
ans = 1

>>> a < b && c!=d
>>>parse error:

syntax error

>>> a < b && c!=d
^

by Malin Christersson under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Sweden License