Files
notes_estom/Matlab/教程/MATLAB5.md
yinkanglong_lab 30f583d779 项目经历整理
2021-04-06 23:30:37 +08:00

31 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# MATLAB的程序控制结构
## >M文件
***
* **分类**
1. 命令文件=脚本文件,没有输入和返回,命令文件可以对工作空间的变量进行操作,文件内部的变量为局部变量,执行后自动清除。
2. 函数文件,可以有输入和返回。
3. 命令文件可以直接运行,函数文件必须以调用的形式运行。
* **建立和打开**
1. 可视化新建
2. edit命令新建
## >程序控制结构
* **使用顺序结构的输入和输出**
1. inputpromt,'s's参数决定是否为字符串
2. disp('string')能够显示字符串或者变量。
3. pause(3)暂停函数,中间是秒数
* **使用分支结构**
1. 单分支的if语句由if决定是否执行
2. 双分支的if-else-end语句
3. 多分支结构if-elseif...else-end
4. switch语句中的case可以加任何数据类型也可以加矩阵向量数组集合
5. try分支是一种试探性的分支提高了程序的容错性。
try 语句组1
catch 语句组2
end
* **使用循环结构**
1. for循环 是在一个范围中循环
2. while循环是一个条件满足循环