我是靠谱客的博主 神勇芝麻,这篇文章主要介绍慕课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



最后

以上就是神勇芝麻最近收集整理的关于慕课matlab学习 第三章-014 switch-case-end 语句的全部内容,更多相关慕课matlab学习内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(126)

评论列表共有 0 条评论

立即
投稿
返回
顶部