(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

本文通过两个示例介绍MATLAB中switch-case语句的使用方法。第一个示例展示了如何根据输入值显示不同的文本信息;第二个示例则演示了如何根据指定的绘图类型绘制不同的图表。
4501

被折叠的 条评论
为什么被折叠?



