MATLAB: Using greater than or less than in ‘switch’ and ‘case’ expressions

function

I don't quite understand how to use the switch and case expressions to calculate when a variable is less than or greater than a particular value. Something like this:
x = 7
switch x
case > 5
disp ('x is greater than 5')
case < 5
disp ('x is less than 5')
otherwise
disp ('error')

Best Answer

use if...elseif..else..end
if x > 5
disp ('x is greater than 5')
elseif x < 5
disp ('x is less than 5')
else
disp ('error')
end
Related Question