.if
Perform element-wise conditional operations with array-type predicates
Since R2023b
Parent Section: equations | intermediates
Syntax
.ifPredicate1
Branch1
.elseifPredicate2
Branch2
.elseBranch3
.end
Description
You can perform element-wise conditional operations with array-type predicates by
using .if
statements. These statements are similar to
if
statements, but in an if
statement,
predicates must be scalar. To evaluate array-type predicates, use .if
statements.
The following rules and restrictions apply:
Every
.if
requires an.else
..elseif
branches are optional. Any subsequent.elseif
branch must have a predicate of the same size and shape as the original.if
branch predicate.Each branch of the
.if-.elseif-.else
statement must match the size and shape of the predicates. Scalar expansion applies.Whether scalar expansion is necessary is determined on a branch-by-branch basis, so using an array in one branch and a scalar in another is allowed.
Units must be commensurate between branches.
Terminate an
.if
statement with the.end
keyword.Output is an array of the same size and shape as the
.if
branch predicate. For multiple return values, each output variable is the same size and shape as the predicate.
Array-type predicates are not supported for:
Conditional sections
Mode charts
Assert statements
Examples
Version History
Introduced in R2023b