📜  MATLAB if-elseif-else … end语句

📅  最后修改于: 2021-01-07 02:11:48             🧑  作者: Mango

MATLAB if-elseif-else … end语句

如果要检查的选项或条件不只一个,请使用elseif关键字。

句法:

if expression
             Statements
elseif expression
 Statements
else
              Statements
end

if … elseif … else … end语句的流程图

范例1:

% program to compare two numbers
% generate random number for your age
n = randi(100,1);
age = 23;
% check the number is greater than your age
if n > age
    disp('i am younger')
elseif n < age
    disp('you are younger')
else
    disp('we are of same age')
end

输出:

n = 9
you are younger