67
SWITCH switch_expr
CASE case_expr,
statement, ..., statement
CASE {case_expr1, case_expr2, case_expr3,...}
statement, ..., statement
...
OTHERWISE,
statement, ..., statement
END
Ví dụ
method = 'Bilinear';
switch lower(method)
case {'linear','bilinear'}
disp('Method is linear')
case 'cubic'
disp('Method is cubic')
case 'nearest'
disp('Method is nearest')
otherwise
disp('Unknown method.')
end
% ket qua la
Method is linear
Ví dụ
diem = 1;
switch diem
case 1
disp('Diem gioi')
case 2
disp('Diem tot')
case 3
disp('Diem kha')
case 4
disp('Diem trung binh')
otherwise
disp('Diem kem.')
end