Real-Time Workshop    

Expression Folding Example

As a simple example of how expression folding affects the code generated from a model, consider the model shown in Figure 9-1.

Figure 9-1: Expression Folding Example Model

With expression folding on, this model generates a single-line output computation, as shown in this MdlOutputs function.

The generated comments indicate the block computations that were combined into a single expression. The comments also document the block parameters that appear in the expression.

With expression folding off, the same model computes temporary results for both Gain blocks and the Product block before the final output, as shown in this MdlOutputs function.

For a example of expression folding in the context of a more complex model, link to the exprfolding demo, or type the following command at the MATLAB prompt.


  Expression Folding Using and Configuring Expression Folding