Main Content

Excluding Unused Paths from Generated Code

In certain situations, you do not need some branches of an: if, elseif, else statement, or a switch, case, otherwise statement in your generated code. For instance:

  • You have a MATLAB® function that performs multiple tasks determined by a control-flow variable. You might not need some of the tasks in the code generated from this function.

  • You have an if/elseif/if statement in a MATLAB function performing different tasks based on the nature (type/value) of the input. In some cases, you know the nature of the input beforehand. If so, you do not need some branches of the if statement.

You can prevent code generation for the unused branches of an if/elseif/else statement or a switch/case/otherwise statement. Declare the control-flow variable as a constant. The code generator produces code only for the branch that the control-flow variable chooses.

Related Topics