当前位置:网站首页>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 .
边栏推荐
- OSPF comprehensive experiment (7.12)
- How to set it to pop up the right-click menu
- What if the computer file cannot be deleted?
- Window 1 - > main window of the application (27)
- Qt使用信号量控制线程(QSemaphore)
- Technology sharing | common proxy tools for interface testing
- What if the computer folder cannot be renamed?
- How to build the protection system of class protection technology of 2022 series of ISO compliance (Part I)
- JS card cascading style image switching JS special effect
- Understand CDN
猜你喜欢

Unity切换到另一个场景的时候,发现该场景变暗了

业务数字化飞速奔跑,管理数字化亟待出发

百度智能云九州区县大脑,描绘城乡新蓝图!

Oracle local network service

"Wei Lai Cup" 2022 Niuke summer multi school training camp 2 supplementary question record (dghjkl)
![[Qt5] a method of multi window parameter transmission (using custom signal slot) and case code download](/img/6d/870add6179f0e3a2f9b719f79594f3.png)
[Qt5] a method of multi window parameter transmission (using custom signal slot) and case code download

EMC EMI磁珠的特性

MPLS -- multi protocol label switching technology

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

Understanding of spark operator aggregatebykey
随机推荐
Deep browser rendering principles
How to close the blocked program process?
The even number of an integer queue is placed in the front, the odd number is placed in the back, and the relative position of the even and odd numbers remains unchanged
JS thoroughly understand this point
JS card cascading style image switching JS special effect
Qt使用信号量控制线程(QSemaphore)
JS cartoon English alphabet typing game source code
Yaml parameter configuration based on singleton mode
Mysql-怎么添加用户和设置权限?
Allure use
CarSim simulation quick start (XII) - Driver Model (2)
Window 1 - > main window of the application (27)
Oracle local network service
Technology sharing | common proxy tools for interface testing
Unity中队列(Queue)的简单使用
These mobile security browsers are more than a little easy to use
Unity切换到另一个场景的时候,发现该场景变暗了
记录一次mycat连接Communications link failure问题解决
File editing component
Solve the inherent defects of CNN! Common CNN architecture ccnn is coming | icml2022