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 嵌套if语句
在MATLAB中嵌套if语句始终是合法的,也就是说可以使用一个嵌套的 if-else语句 if 或 elseif 语句在另一个 if 或 elseif 语句。
MATLAB嵌套 if 语句语法:
详细语法如下:
if <expression 1>
% Executes when the boolean expression 1 is true
if <expression 2>
% Executes when the boolean expression 2 is true
end
end
可以嵌套 elseif 或其他类似的方式,因为已经嵌套 if 语句。
详细例子如下:
在MATLAB中建立一个脚本文件,并输入下面的代码:
a = 100;
b = 200;
% check the boolean condition
if( a == 100 )
% if condition is true then check the following
if( b == 200 )
% if condition is true then print the following
fprintf('Value of a is 100 and b is 200
' );
end
end
fprintf('Exact value of a is : %d
', a );
fprintf('Exact value of b is : %d
', b );
运行该文件,它显示的结果如下:
Value of a is 100 and b is 200
Exact value of a is : 100
Exact value of b is : 200