Matlab中switch_case_otherwise语句详解
switch case语句的表达形式为:
switch 变量
case 1
action 1
case 2
action 2
case 3
action 3
end
Switch case语句只能判断一个确定的数值,case后面只能是确定的数,多个数可以用{ }括起来
下面将if语句和switch case语句放在一起进行对比:
输入0-10以内的数字,如果是9和10,对应的等级是A,8是B,7是C,6是D,除了8、7、6之外均是E。
表达形式:
num=input('please input a number:')
if num > 10 || num < 0
disp('this num is not a approporiate value')
elseif num == 10 || num == 9disp('your grade is A')
elseif num == 8disp('your grade is B')
elseif num == 7disp('your grade is C')
elseif num == 6disp('your grade is D')
elsenum ~= 10 && num ~= 9 && num ~= 8 && num ~= 7 && num ~= 6disp('your grade is E')
end
switch case语句来表达:
num=input('please input a number:')
switch num
case 10disp('your grade is A')case 9disp('your grade is A')
case 8 disp('your grade is B')
case 7 disp('your grade is C')case 6 disp('your grade is D')otherwisedisp('your grade is E')
但是上面的switch case语句没有对num的取值区间0-10进行限定,现在对其完善:
num = input('please input a number:')
if num > 10 || num < 0disp('this num is not a approporiate value')
else %num属于0到10
switch num
case 10disp('your grade is A')case 9disp('your grade is A')
case 8 disp('your grade is B')
case 7 disp('your grade is C')case 6 disp('your grade is D')otherwisedisp('your grade is E')
end
end
case后面只能是确定的数,多个数可以用{ }括起来
num = input('please input a number:')
if num > 10 || num < 0disp('this num is not a approporiate value')
else %num属于0到10
switch num
case {10,9}disp('your grade is A')
case 8 disp('your grade is B')
case 7 disp('your grade is C')case 6 disp('your grade is D')otherwisedisp('your grade is E')
end
end
Matlab中switch_case_otherwise语句详解相关推荐
- Matlab中 pdist 函数详解
学习笔记,仅供参考,有错必纠 转载自:Matlab中 pdist 函数详解(各种距离的生成); pdist Pairwise distance between pairs of objects. Sy ...
- matlab中xcorr函数详解
Matlab中xcorr函数详解 引言 在matlab中查找相关函数时,找到了xcov函数和xcorr函数,仔细看了帮助文档,发现虽然计算公式不一样,但是两个函数用法相同,计算出的值也相同,于是在翻了 ...
- Java中if语句详解
Java if语句 **格式一:if(条件表达式) {语句体;}**条件表达式最终的结果只能是boolean类型,要么是true,要么是false执行流程:如果程序执行到if语句的时候,会去看条件表达 ...
- MATLAB中逻辑类型详解
逻辑类型 Matlab中存储逻辑变量的类型有两种,为true和false,分别由1和0来表示. 函数logical() 可以将任何非零的数值转化为true,将数值0转化为false. a=3;b=0; ...
- 什么事java中hql语句,hibernate中hql语句详解
之前给大家讲了一下hibernate分页查询的内容,那么下面就要接着给大家对hibernate中hql语句方面的知识进行一下详细的讲解,一起来了解一下吧. 刚开始做项目的时候,项目当中的hql语句就是 ...
- matlab中dnf,图文详解DNF里的边际效应 用数据告诉你一切
大家好,我是酸のLemonade.前几天发表了一篇关于暴风眼刷图的文章,得到了大家的支持,楼主深表感激!有些朋友主动留下了QQ,我也加了,共同交流柔道的刷图问题.有些朋友在游戏里加了我好友,也有些要求 ...
- SQL中SELECT语句详解
本篇文章讲述SQL语句中的SELECT查询语句,以供参考,如有错误或不当之处还望大神们告知. 简单查询SELECT-FROM 用于无条件查询单张表中的行或列 假设有表如图所示 查询名字叫 '叶清逸' ...
- Matlab中fft函数详解
FFT函数 Y = fft(x) 如果x是向量,则fft(x)返回该向量的傅里叶变换 如果x是矩阵,则fft(x)将x的各列视为向量,并返回每列的傅里叶变换. 如果x是一个多维数组,则 fft(X) ...
- matlab中如何实现递归,Matlab中递归函数调用详解
利用单独的M文件并递归地调用该文件,既可以避免多个M文件的复杂性,又可以利用函数的优点.使用开关 switches或if elseif语句,可将回调函数装入调用函数内. 通常这样一种函数调用的结构为 ...
最新文章
- html 未来元素绑定事件,jquery on如何给未来元素绑定事件?
- 实验十:程序结构与数组 8、数组实训
- HTML与CSS基础之兄弟元素(六)
- linux如何关掉正在启动的服务器,Linux服务管理(如何关闭或禁用不需要的服务)?...
- JavaScriptCore.framework基本用法(一)
- JAVA动态加载JAR包执行程序
- (Greedy approach)Find longest word in dictionary that is a subsequence of a given string
- 你看那个人他像一条狗
- Java开发过程中遇到的问题及解决方法
- oracle 19c ora-01017,Oracle 19c RMAN 连接PDB ORA-01017 错误解决方法
- 异常处理·psftp·local unable to open
- 微信公众号调用扫一扫,使扫一扫支持扫PDF417格式的条码
- 谷歌打开微信定位服务器地址,使用Chrome修改user agent模拟微信内置浏览器
- cd linux安装驱动程序,给CDlinux增添网卡驱动失败的原因和对策
- 罗振宇《时间的朋友2018》跨年演讲全文
- 如何使用智遥工作流为SAP节省License实例
- 木鱼网址缩短服务 短域名生成网站源码
- linux的系统文件位置,剖析Linux系统中的文件系统路径
- 删除重复记录并修改索引
- html轮廓线怎么取消,c4d这些线条怎么取消掉