慕课matlab学习 第三章-014 switch-case-end 语句

% 慕课matlab学习 第三章-014
% 02-用switch语句实现选择结构



% 第三节 程序流程控制
% 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}  % 1245  四个条件可以运行  { } 包含多个分支 
        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



  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值