Why do inlined Global Data Store initial values get initialized to all zeros and then reinitialized to the actual values in the generated code using Simulink Coder 8.2 (R2012a)?
Show older comments
I have a model which contains a Stateflow Global Data Store variable tied to a Simulink.Signal (or mpt.Signal) object. This object has its 'InitialValue' field set to a non-zero value -- in my case, this is [1 2 3].
My generated code inlines parameters so that the object associated with this Simulink.Signal is initialized to have the initial value {1, 2, 3} (in C syntax).
What I noticed was that the generated code will initialize the array to be {0, 0, 0}. If I choose a different initial value (for example, {1, 2, 3}), the code will first initialize the array to all zeros and then add in the other initial values.
For example, my code looks as follows:
GlobalDataVector[0] = 0.0;
GlobalDataVector[1] = 0.0;
GlobalDataVector[2] = 0.0;
/* other code here */
GlobalDataVector[0] = 1.0;
GlobalDataVector[1] = 2.0;
GlobalDataVector[2] = 3.0;
Why is this?
Accepted Answer
More Answers (0)
Categories
Find more on Simulink Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!