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

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 25 de En. de 2025
Editada: MathWorks Support Team el 31 de En. de 2025
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:

Más respuestas (0)

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by