当前位置: 首页 > news >正文

MATLAB 嵌套switch语句||MATLAB while循环

MATLAB 嵌套switch语句

在 MATLAB 中嵌套 switch 语句是可能的,可以在 switch 一部分外嵌套 switch 语句序列。即使 case 常量的内部和外部的 switch 含有共同的值,也不算冲突出现。

MATLAB嵌套switch语句语法

嵌套switch语句的语法如下:

switch(ch1) case 'A' fprintf('This A is part of outer switch');switch(ch2) case 'A'fprintf('This A is part of inner switch' );case 'B'  fprintf('This B is part of inner switch' );end   
case 'B'
fprintf('This B is part of outer switch' );
end

详细例子:

在MATLAB中建立一个脚本文件,并输入下面的代码:

a = 100;
b = 200;
switch(a) case 100 fprintf('This is part of outer switch %d
', a );switch(b) case 200fprintf('This is part of inner switch %d
', b );end
end
fprintf('Exact value of a is : %d
', a );
fprintf('Exact value of b is : %d
', b );

当运行该文件时,它会显示:

This is part of outer switch 100
This is part of inner switch 200
Exact value of a is : 100
Exact value of b is : 200

MATLAB while循环

MATLAB的 while 循环会重复执行 while  end 语句间的运算式,只要表达式为 true

MATLAB while循环语法

在MATLAB 中 while循环的语法如下:

while <expression><statements>
end

while 循环反复执行程序语句只要表达式为 true。

当结果不为空,并包含所有非零元素(逻辑或实际数字),表达式为 true ;否则,表达式为 false。

详细例子

在MATLAB中建立一个脚本文件,并输入以下代码:

a = 10;
% while loop execution 
while( a < 20 )fprintf('value of a: %d\n', a);a = a + 1;
end

运行该文件,显示结果如下:

value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19

相关文章:

  • C#,数值计算——插值和外推,分段线性插值(Linear_interp)的计算方法与源程序
  • MySQL索引:作用、类型、设计原则、优化策略与常见陷阱
  • python实现炫酷的屏幕保护程序
  • Three.js相机模拟
  • 数据结构 并查集
  • 9 HDFS架构剖析
  • 【Linux】线程互斥
  • 记GitLab服务器迁移后SSH访问无法生效的问题解决过程
  • 解决docker运行elastic服务端启动不成功
  • 记一次线上bug排查-----SpringCloud Gateway组件 请求头accept-encoding导致响应结果乱码
  • Netty源码学习4——服务端是处理新连接的netty的reactor模式
  • Flink 运行架构和核心概念
  • 工具及方法 - 多邻国: Duolingo
  • pytho你-opencv划痕检测
  • 基础课6——开放领域对话系统架构
  • @angular/forms 源码解析之双向绑定
  • HashMap剖析之内部结构
  • iOS小技巧之UIImagePickerController实现头像选择
  • Javascript设计模式学习之Observer(观察者)模式
  • js
  • Making An Indicator With Pure CSS
  • PHP 小技巧
  • 分布式任务队列Celery
  • 罗辑思维在全链路压测方面的实践和工作笔记
  • 为物联网而生:高性能时间序列数据库HiTSDB商业化首发!
  • 小程序开发中的那些坑
  • 3月27日云栖精选夜读 | 从 “城市大脑”实践,瞭望未来城市源起 ...
  • 正则表达式-基础知识Review
  • !! 2.对十份论文和报告中的关于OpenCV和Android NDK开发的总结
  • # 20155222 2016-2017-2 《Java程序设计》第5周学习总结
  • #13 yum、编译安装与sed命令的使用
  • #HarmonyOS:Web组件的使用
  • #我与Java虚拟机的故事#连载14:挑战高薪面试必看
  • #周末课堂# 【Linux + JVM + Mysql高级性能优化班】(火热报名中~~~)
  • $.ajax()
  • $.ajax中的eval及dataType
  • (Python) SOAP Web Service (HTTP POST)
  • (分类)KNN算法- 参数调优
  • (附源码)spring boot公选课在线选课系统 毕业设计 142011
  • (附源码)ssm高校升本考试管理系统 毕业设计 201631
  • (机器学习-深度学习快速入门)第三章机器学习-第二节:机器学习模型之线性回归
  • (剑指Offer)面试题41:和为s的连续正数序列
  • (转)用.Net的File控件上传文件的解决方案
  • (转)自己动手搭建Nginx+memcache+xdebug+php运行环境绿色版 For windows版
  • (轉貼) VS2005 快捷键 (初級) (.NET) (Visual Studio)
  • (轉貼) 蒼井そら挑戰筋肉擂台 (Misc)
  • .【机器学习】隐马尔可夫模型(Hidden Markov Model,HMM)
  • .CSS-hover 的解释
  • .form文件_一篇文章学会文件上传
  • .net Application的目录
  • .Net core 6.0 升8.0
  • .NET 回调、接口回调、 委托
  • .NET/ASP.NETMVC 大型站点架构设计—迁移Model元数据设置项(自定义元数据提供程序)...
  • .NET中使用Redis (二)
  • /boot 内存空间不够