## 算法介紹
% 開關切換分支機構的基本形式
%{
switch expression % 設置開關條件1
case Vorc1 % 分支情況1
(commands1)
case Vorc2
(commands2)
......
case Vorcn
(commandsn)
otherwise
(commanddefault)
end
%}
算法應用
grade = 'B';
switch(grade)
case 'A'
fprintf('Excellent!\n' );
case 'B'
fprintf('Well done\n' );
case 'C'
fprintf('Well done\n' );
case 'D'
fprintf('You passed\n' );
case 'F'
fprintf('Better try again\n' );
otherwise
fprintf('Invalid grade\n' );
end