|MATLAB Function Reference|
Conditionally execute statements
expression1 evaluates as
true, MATLAB executes the one or more commands denoted here as
true expression has either a logical 1 (
true) or nonzero value. For nonscalar expressions, (for example, is matrix A less then matrix B),
true means that every element of the resulting matrix has a
true or nonzero value.
Expressions usually involve relational operations such as
(count < limit) or
isreal(A). Simple expressions can be combined by logical operators (
~) into compound expressions such as
(count < limit) & ((height - offset) >= 0).
if for more information.
if, with a space between the
else and the
if, differs from
elseif, with no space. The former introduces a new, nested
if, which must have a matching
end. The latter is used in a linear sequence of conditional statements with only one terminating
The two segments shown below produce identical results. Exactly one of the four assignments to
x is executed, depending upon the values of the three logical expressions,
Here is an example showing
k=5 you get the matrix
return, relational operators, logical operators (elementwise and short-circuit)
© 1994-2005 The MathWorks, Inc.