MATLAB: How to initialize signals with parameters in generated code using Real-Time Workshop Embedded Coder 5.3 (R2009a)

codeevaluatedgenerationinitialinline()simulink codertunablevalue

When generating code, I'm using my own custom storage class TLC for my signals (measurement categories). Some of these signals will be initialized by 'InitialValue' property of the storage class. Even if I define the 'InitialValue' to be another variable, the generated code always hard-codes the value at code generation time.
Is it possible to define a variable as initial value to the signals in my model?

Best Answer

The ability to define the initial value of a signal to be variable is not available in Real-Time Workshop Embedded Coder 5.3 (R2009a). The expression in the 'Intial Value' option will be always evaluated at the time of code generation. This is due to the code generation philosophy that Generated code results should match the Simulation results.
To work around this issue, try adding the initialization code manually in the 'Custom Code' pane in RTW configuration parameters:
myInputSignal =parameter;
where 'myInputSignal' is the name of the signal and 'parameter' is the name of parameter that you want the signal to be initialized to in the generated code.
However, this will fail in some edge cases where the signal object (i.e. Simulink.Signal, mpt.Signal, or some custom object) is reused in multiple locations of model since name mangling may occur.