How to force Embedded Coder to unroll the generated for loop of "For Each Subsystem" in generated code?
古いコメントを表示
I am using for each subsystem to simulate and generate the embedded code for embedded hardware.
I have attached the simple example of For Each Subsystem and generated code.
I tried different Code generation Optimazation settings to unroll the loop in generated code but I am unable to solve it.

I tried also different values for loop unrolling threshold but this does not help or may be I am doing something wrong.
Does anyone know how to solve this issue?
Thank you.
回答 (1 件)
Harsh
2025 年 4 月 22 日
The code generator unrolls loops when the number of iterations is below the threshold set in "Loop unrolling threshold" in advanced parameters. In the attached "For_Each_Subsystem_Example", there are iterations present in the for loop. Therefore you can set the value for "Loop unrolling threshold" as 4. There are two ways to do this:
- Go to "Code Generation" > "Optimization" > "Advanced Parameters" and set the "Loop unrolling threshold" as 4.

- Use the "set_param" function in command line.
set_param('For_Each_Example', 'RollThreshold', 4)
Here's how the generated code looks like after optimization -

カテゴリ
ヘルプ センター および File Exchange で Simulink Coder についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!