How to force Embedded Coder to unroll the generated for loop of "For Each Subsystem" in generated code?

5 ビュー (過去 30 日間)
SG
SG 2025 年 3 月 20 日
回答済み: Harsh 2025 年 4 月 22 日
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
Harsh 2025 年 4 月 22 日
Hi @SG,
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 -

カテゴリ

Help Center および File ExchangeDeployment, Integration, and Supported Hardware についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by