% 慕课matlab学习 第三章-014
% 02-用switch语句实现选择结构
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50% 第三节 程序流程控制 % 02-用switch语句实现选择结构 % switch case 和 otherwise x=input('请输入x 的值 X=?') switch fix(x) case 2 % case 2 实际 disp(111); case 3 disp(222) % 3 case {1,2,4,5} % 1,2,4 ,5 四个条件可以运行 { } 包含多个分支 disp(333) otherwise disp(444) end % eg % 例1 输入一个英文单词,判断它是否以元音字母开头。 c=input('请输入一个单词:' ,'S') switch c(1) case{'A','E','I','O','U','a','e','i','o','u'} disp([c,'以元音字母开头']) otherwise disp([c,'以辅音字母开头']) end % 使用switch-case 表达式来进判断空气质量好坏 g=input('请输入PM2.5值: ') switch fix(g) case num2cell(0:34) disp('空气质量优') case num2cell(35:74) disp('空气质量良好') case num2cell(75:114) disp('空气质量轻度污染') case num2cell(115:149) disp('空气质量中度污染') case num2cell(150:249) disp('空气质量重度污染') otherwise disp('空气质量严重污染') end
最后
以上就是神勇芝麻最近收集整理的关于慕课matlab学习 第三章-014 switch-case-end 语句的全部内容,更多相关慕课matlab学习内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复