.if
Perform element-wise conditional operations with array-type predicates
Since R2023b
Parent Section: equations | intermediates
Syntax
.ifPredicate1Branch1.elseifPredicate2Branch2.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
.ifrequires an.else..elseifbranches are optional. Any subsequent.elseifbranch must have a predicate of the same size and shape as the original.ifbranch predicate.Each branch of the
.if-.elseif-.elsestatement 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
.ifstatement with the.endkeyword.Output is an array of the same size and shape as the
.ifbranch 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