(1)单个的就如同C语言中的一样,不过在和switch使用的时候case后不用接:
n = input('Enter a number: ');
switch n
case -1
disp('negative one')
case 0
disp('zero')
case 1
disp('positive one')
otherwise
disp('other value')
end
(2)多个的使用就用花括号
x = [12 64 24];
plottype = 'pie3';
switch plottype
case 'bar'
bar(x)
title('Bar Graph')
case {'pie','pie3'}
pie3(x)
title('Pie Chart')
otherwise
warning('Unexpected plot type. No plot created.')
end