MATLAB决策制定 - Matlab教程

决策结构要求程序员指定一个或多个条件进行评估或测试程序,沿一条或多条语句执行,如果条件被确定为真,以及可选,其他要执行的语句,如果条件确定是假的 (false)。

以下是一个典型的决策结构,发现在大多数编程语言的一般形式:

Decision making statements in MATLAB

MATLAB 提供以下类型的决策报表。点击以下链接,以检查他们的细节:

语句 描述
if ... end statement An if ... end statement consists of a boolean expression followed by one or more statements.
if...else...end statement An if statement can be followed by an optional else statement, which executes when the boolean expression is false.
If... elseif...elseif...else...end statements An if statement can be followed by an (or more) optional elseif...and an else statement, which is very useful to test various condition.
nested if statements You can use one if or elseif statement inside another if or elseif statement(s).
switch statement A switch statement allows a variable to be tested for equality against a list of values.
nested switch statements You can use one swicth statement inside another switch statement(s).