当前位置:网站首页>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 .
边栏推荐
- Awk from introduction to earth (16) discussion on the types of awk variables -- about the two types of numbers and strings
- 聊一聊数据库的行存与列存
- uniapp的swiper动态设置current值不生效解决办法
- Enum class
- OpenTSDB-时序数据库
- Deep browser rendering principles
- Common solutions for distributed ID - take one
- Yaml parameter configuration based on singleton mode
- Fxksmdb.exe process description
- Understand the propagation process of EMI electromagnetic interference through five diagrams - the influence of square wave steepness on high-frequency components, the spectrum graph from time sequenc
猜你喜欢

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

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

03 | project deployment: how to quickly deploy a website developed based on the laravel framework

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

MCU IO port controls 12V voltage on and off, MOS and triode circuit

OSPF comprehensive experiment (7.12)

Characteristics of EMC EMI beads

Tell you step by step what you need to do to apply for PMP? What should I do?

Parse tree structure JS

See how Google uses pre training weights in target detection tasks | CVPR 2022
随机推荐
03 | project deployment: how to quickly deploy a website developed based on the laravel framework
Spiral matrix
单片机IO口控制12V电压通断,MOS和三极管电路
Freezing and thawing of pytoch
Deep browser rendering principles
js卡片层叠样式的图片切换js特效
[chart component kit] Shanghai daoning provides developers with steema download, trial and tutorial
[pyqt] pyqt development experience_ How to find events and methods of controls
Mysql, how can we get the number of rows affected by the query?
网口网络水晶头RJ45、POE接口定义线序
How to use QT help documents
Allure use
Is the salary of test / development programmers unbalanced? Busy life, all kinds of job hopping
One key switch circuit
Enum class
OpenTSDB-时序数据库
Swm32 series tutorial 5-adc application
Creation of status bar (29)
Prescan quick start to proficient in lecture 17, speed curve editor
[environment configuration] ppyoole trains its own data set (for its own use)