当前位置:网站首页>Matlab (3) matlab program flow control statement
Matlab (3) matlab program flow control statement
2022-07-28 08:31:00 【Kaizhi~】
Catalog
Sequential structure
if sentence
MATLAB Of if Statements and C Language similarity , The difference lies in :
- else and if There is no space between
- The expression does not need brackets "(“ and ”)" Cover up
- Keyword is required at the end end Express
- Statement groups do not need braces "{" and “}” Cover up ( Because there will be end as well as else And other keywords )
Examples are as follows
if expression
Statement group
elseif expression 2
Statement group 2
else
Statement group 3
end
The structure flow control statement is in m Files and command line windows can be written , When writing in the command line window , The lower left corner will show “ Continue entering statements ” The words... , Until input end And press enter , Will start to execute .
switch sentence
MATLAB Of switch Statements and C Language similarity , The difference lies in :
- The final default option is otherwise instead of default
- case No colon is required after the statement ":"
- case The constant expression in the statement can be an array ( Using array names 、{} The enclosed elements are ok )
- Keyword is required at the end end Express
- case Statement groups do not need braces "{" and “}” Cover up
Examples are as follows
switch expression
case Constant expression 1
Statement group 1
case Constant expression 2
Statement group 2
default
Statement group 3
end
MATLAB Of switch Unwanted break, Instead, execute any statement group and exit .
Loop structure
for sentence
MATLAB Of for Examples of statements are as follows
for Loop variable = Array expression
The loop body
end
among , Array expressions can use array names , At this time, in each cycle , The cyclic variable is equal to the element corresponding to the subscript . Of course , Generally, colon expression can also be used as array expression ,C Linguistic for(num=0;num<10;num++) And MATLAB Of for num=0:1:9 equivalent , Of course , Personal feeling C Linguistic for Sentences are more flexible ,( After all, conditions are easier to write , And the elements corresponding to subscripts can be used in arrays in the loop body ), Of course ,MATLAB Of for Statements can also implement C Functions in language .( Add a judgment at most and break)
while sentence
MATLAB Of while Examples of statements are as follows , And C The language is as like as two peas. .( But expressions don't need parentheses )
while expression
The loop body
end
Other statements
break
Generally used in loop statements , Used to terminate the innermost loop .
continue
Generally used in loop statements , Used to skip this loop .
return
Make the executing function exit normally
try…catch…
Format :
try
Statement group 1
catch
Statement group 2
end
try…catch… The statement is actually the same as the following if The structure is similar to , Execute statement group 1, If there is an error, execute the statement group 2.( If normal, do not execute the statement group 2, It's skipping )
if ! Statement group 1
Statement group 2
end
try…catch… The use of can improve the fault tolerance of the program and the flexibility of program design , Instead of jumping to the dead cycle or stopping operation when encountering errors .
边栏推荐
- DCL singleton mode
- [leetcode] 24. Exchange nodes in the linked list in pairs
- XSS knowledge points and 20 character short domain name bypass
- Unity中队列(Queue)的简单使用
- How do we run batch mode in MySQL?
- What if the computer desktop icon has a small yellow lock?
- pyspark更改列顺序存入iceberg数据库
- "Wei Lai Cup" 2022 Niuke summer multi school training camp 2 supplementary question record (dghjkl)
- 记录一次mycat连接Communications link failure问题解决
- CarSim simulation quick start (XI) - Driver Model (1)
猜你喜欢
![In the task manager, the CPU speed displayed is greater than its maximum speed [main frequency]](/img/90/a3f56ef8f08a8735febba16af227f9.png)
In the task manager, the CPU speed displayed is greater than its maximum speed [main frequency]

Common solutions for distributed ID - take one

【13】 Adder: how to build a circuit like Lego (Part 1)?

单片机IO口控制12V电压通断,MOS和三极管电路

PMP practice once a day | don't get lost in the exam -7.13

Meituan Er Mian: why does redis have sentinels?

Es6: template string

聊一聊数据库的行存与列存

Solve the inherent defects of CNN! Common CNN architecture ccnn is coming | icml2022

jquey的基础语法
随机推荐
@The role of documented
DCL singleton mode
Opentsdb time series database
What if the computer desktop icon has a small yellow lock?
pyspark更改列顺序存入iceberg数据库
Prescan quick start to master the transportation elements in lesson 14, prescan
JS thoroughly understand this point
How to build the protection system of class protection technology of 2022 series of ISO compliance (Part I)
[book club issue 13] Chapter 2 notes on the packaging format and coding format of video files
Huawei Senior Engineer -- BGP routing filtering and community attributes
Understand CDN
Can‘t connect to server on ‘IP‘ (60)
Redis of non relational database [detailed setup of redis cluster]
A group of South University students rely on science and technology to go to sea, with an annual income of 1billion
解决EMC、EMI传导干扰的八大方法
百度智能云九州区县大脑,描绘城乡新蓝图!
File editing component
UE4 engine customizes screenpass and MRT output
Talk about row storage and column storage of database
c语言中函数的介绍(血书20000字!!!!)