Relational Operators

 
  • == : Equal to
  • ~= : Not equal to (MATLAB & Octave)
  • != : Not equal to (Octave only)
  • > : Greater than
  • < : Less than
  • >= : Greater than or equal to
  • <= : Less than or equal to

a = 3
A = [4 0 5 9]
B = [1 2; 3 4]
C = [3 4; 5 6]
a == 2  % false
>> 0  % (logical)
a ~= 2  % true
>> 1
a != 2  % (Octave only)
>> 1
a > 3
>> 0  % (logical)
a >= 3
>> 1  % (logical)
A >= 3
>>  1   0   1   1   % (1×4 logical array)
find(A >= 3)
% Find indices and values of nonzero elements
>>  1    3    4
B >= 2
>> % 2x2 logical array
  0   1
  1   1
C <= 4
>>  % 2x2 logical array
  1   1
  0   0
B >= 2 & B < 4
>>  % 2x2 logical array
  0   1
  1   0
B >= 2 & C <= 4
>>  % 2x2 logical array
  0   1
  0   0