Contents

Check if x is in the interval (0,2)

x = 1.1;
if x > 0 && x < 2 % and conditional
    sprintf('%f is inside (0,2)!',x)
end

% Check if x is outside (0,2)
x = 2.1;
if x <= 0 || x >= 2 % or conditional
    sprintf('%f is outside (0,2)!',x)
end
ans =

1.100000 is inside (0,2)!


ans =

2.100000 is outside (0,2)!

Notice the different out put if we use fprintf()

x = 1.1;
if x > 0 && x < 2 % and conditional
    fprintf('%f is inside (0,2)! \n',x)
end

% Check if x is outside (0,2)
x = 2.1;
if x <= 0 || x >= 2 % or conditional
    fprintf('%f is outside (0,2)! \n',x)
end
1.100000 is inside (0,2)! 
2.100000 is outside (0,2)!