Why do conditional statements get optimized out in the code generated by Embedded Coder?

3 ビュー (過去 30 日間)
I have a MATLAB Function Block in my model. From the body of a sub-function in that MATLAB Function Block, an entire else-branch is missing in the C code. Why would Embedded Coder apply optimization to my if-else statement?
if( (my_var >= uint16(0)) && (my_var <= uint16(100)) ) %code here else %code here - completely missing in C code end

採用された回答

MathWorks Support Team
MathWorks Support Team 2025 年 1 月 25 日
編集済み: MathWorks Support Team 2025 年 1 月 31 日
This is an expected optimization performed by Embedded Coder. For example, the code could be written such that "my_var" can never be outside the range [0, 100], and so Embedded Coder optimized it out. Another possible reason could be related to the 'Optimize using the specified minimum and maximum values' (UseSpecifiedMinMax) setting. To access the release-specific documentation for this setting, execute the following command in the MATLAB R2019b command window:
>> web(fullfile(docroot, 'rtw/ref/optimize-using-the-specified-minimum-and-maximum-values.html'))
The if-statement does a range check on "my_var", which is why it could be that Embedded Coder is performing the min/max optimization. There are a few different places a user could be setting the min/max values:
1) On the root inport:
2) In the Ports and Data Manager of the MATLAB Function Block:
3) In a Simulink.Signal object mapped to that input signal:
Please follow the below link to search for the required information regarding the current release:

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Coder についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by