Why does my generated code contain unnecessary calls to the Rte in the initialize function?

I have an outport in my model which I have configured as NV port. I am getting the correct Rte_Write() calls in the generated code, but I get extra unnecessary Rte calls in the initialize function. 
Any idea why this may be happening?      

 Accepted Answer

It seems that your port contains non-zero initial conditions, which you can see as the little "IC" text over the input signal:  
 
In the block parameters for the port, the "Source of initial output value" option is configured to "Input signal". Since the initial conditions are non-zero, we include an extra Rte_Write() during initialization to set the initial conditions. 
In order to avoid this, you can choose the option "Dialog" for "Source of initial output value", so you can manually select zero initial conditions in the block parameters for the port: (for the "Output when disabled", either "reset" or "held" would give the same result, so this option depends on your specific modelling requirements) 
 
Doing so shall guide the code generator to optimize away redundant zero initialization code. However, if a non-zero initial condition is necessary, it's important to investigate the source of this value rather than simply overriding it with 0, as this might affect the functionality of the generated code. 
 

More Answers (0)

Products

Release

R2022b

Community Treasure Hunt

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

Start Hunting!