MATLAB 教程
- 第1节:MATLAB 介绍
- 第2节:MATLAB 安装
- 第3节:MATLAB 基本语法
- 第4节:MATLAB 变量
- 第5节:MATLAB 命令
- 第6节:MATLAB M-Files
- 第7节:MATLAB 数据类型
- 第8节:MATLAB 运算符
- 第9节:MATLAB 算术运算
- 第10节:MATLAB 逻辑运算
- 第11节:MATLAB 关系运算
- 第12节:MATLAB 位运算
- 第13节:MATLAB 集合操作
- 第14节:MATLAB 决策制定
- 第15节:MATLAB if...end 语句
- 第16节:MATLAB if...else...end 语句
- 第17节:MATLAB if...elseif...elseif...else...end 语句
- 第18节:MATLAB 嵌套if语句
- 第19节:MATLAB switch语句
- 第20节:MATLAB 嵌套switch语句
- 第21节:MATLAB 循环类型
- 第22节:MATLAB while循环
- 第23节:MATLAB for循环
- 第24节:MATLAB 嵌套循环
- 第25节:MATLAB break语句
- 第26节:MATLAB continue语句
- 第27节:MATLAB 向量
- 第28节:MATLAB 向量的加法和减法
- 第29节:MATLAB 标量向量乘法
- 第30节:MATLAB 转置向量
- 第31节:MATLAB 追加向量
- 第32节:MATLAB 向量的模
- 第33节:MATLAB 向量点积
- 第34节:MATLAB 等差元素向量
- 第35节:MATLAB 矩阵
- 第36节:MATLAB 矩阵的加法和减法
- 第37节:MATLAB 除法(左,右)矩阵
- 第38节:MATLAB 矩阵标量操作
- 第39节:MATLAB 矩阵的转置
- 第40节:MATLAB 串联矩阵
- 第41节:MATLAB 矩阵乘法
- 第42节:MATLAB 矩阵的行列式
- 第43节:MATLAB 逆矩阵
- 第44节:MATLAB 数组
- 第45节:MATLAB 冒号符号
- 第46节:MATLAB 数字
- 第47节:MATLAB 字符串
- 第48节:MATLAB 函数
- 第49节:MATLAB 数据导入
- 第50节:MATLAB 数据导出
- 第51节:MATLAB 绘图
- 第52节:MATLAB 图形
- 第53节:MATLAB 代数
- 第54节:MATLAB 微积分
- 第55节:MATLAB 多项式
- 第56节:MATLAB 变换
- 第57节:MATLAB GNU Octave教程
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 200
fprintf('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