MATLAB: How to keep Embedded Coder from optimizing the if-else statement in a MATLAB Function Block

Embedded Coderusespecifiedminmax

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 using R2019b, although there is no reason why the if-branch should always be true.
if( (my_var >= uint16(0)) && (my_var <= uint16(100)) )
  %code here
else
%code here - completely missing in C code
end
end

Best Answer

If the code is written such that "my_var" can never be outside the range [0, 100], it is expected behavior that Embedded Coder optimizes the else-branch out. See the following MATLAB Answers post for more information:
But if a user absolutely wants that else statement to appear in the generated code, one option is to put the entire if-else statement in a local function and use "coder.inline":
That might look something like this:
function res = myLocalFunc(in)
coder.inline('never');
if( (my_var >= uint16(0)) && (my_var <= uint16(100)) )
  %code here

else
%code here
end
end
Then, they could call "myLocalFunc" in place of the if-else statement in their MATLAB Function block.