Exercises Switch Case and Operators Matlab
Exercises Switch Case and Operators Matlab
1
MATLAB 2022- 2023 الجامعة التكنولوجية
المرحلة الثانية قسم تكنولوجيا النفط
Example2: Example3:
x = 222, y = 3; x = 222, y = 3;
switch x switch x
case (x==y) case x*(x==y)
disp('x and y are equal'); disp('x and y are equal');
case (x>y) case x*(x>y)
disp('x is greater than y'); disp('x is greater than y');
otherwise otherwise
disp('x is less than y'); disp('x is less than y');
end end
Example4: Example5:
a=input('enter number'); a=input('enter number');
b=a;
switch true switch a
2
MATLAB 2022- 2023 الجامعة التكنولوجية
المرحلة الثانية قسم تكنولوجيا النفط
Example 6:
clc
clear
Entergrade=input('enter grade letter A,B,C,D,F or others ','S');
switch(Entergrade)
case 'A'
fprintf('Excellent performance!\n' );
case 'B'
fprintf('Well done performance\n' );
case 'C'
fprintf('Very Good performance\n' );
case 'D'
fprintf('You passed.. Congratulations\n' );
case 'F'
fprintf('Better luck next time\n' );
otherwise
fprintf('Invalid grade. Please enter correct value\n' );
end