Main Content
cgsl_0202: Usage of For, While, and For Each subsystems with vector signals
ID: Title | cgsl_0202: Usage of For, While, and For Each subsystems with vector signals | ||
---|---|---|---|
Description | When developing a model for code generation, | ||
A | Use For, While, and For Each subsystems for calculations that require iterative behavior or operate on a subset (frame) of data. | ||
B | Avoid using For, While, or For Each subsystems for basic vector operations. | ||
Rationale | A, B | Avoid redundant loops. | |
See Also |
| ||
Last Changed | R2010b | ||
Examples | The recommended
method for preceding calculation is to place the Gain block outside
the For Subsystem. If the calculations are required as part of a larger
algorithm, you can avoid the nesting of Recommended for (s1_iter = 0; s1_iter < 10; s1_iter++) { RecommendedOut[s1_iter] = 2.3 * vectorInput[s1_iter]; } A common mistake is to embed basic
vector operations in a For, While, or For Each subsystem. The following
example includes a simple vector gain inside a For subsystem, which
results in unnecessary nested | ||
Not Recommended for (s1_iter = 0; s1_iter < 10; s1_iter++) { for (i = 0; i < 10; i++) { NotRecommendedOut[i] = 2.3 * vectorInput[i]; } } |