How can I explicitly initialize specific zero-valued Data Store Memories?

4 views (last 30 days)
I am generating code for a model using Embedded Coder. This model contains some "Data Store Memory" (DSM) blocks that may be zero-valued at initialization. I am aware that zero-valued initializations can be omitted if I check the setting:
Model Configuration Parameter > Code Generation > Optimization > Remove internal data zero initialization
This disables all initialization lines in the generated code if the DSM block is initialized to be zero. However, this is quite inflexible because in some cases, omitting the initialization is beneficial e.g. for a large array that does not need to be read. In other cases, I require the initialization e.g. I need to compare the value drawn from the data store using "Data Store Read" block.
Is there a way to manually select certain zero-valued DSM blocks to explicitly initialize?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 14 Oct 2022
Starting from MATLAB R2022a, zero-valued DSM blocks initialized inside the "Initialize Function" block retain their initialization in generated code even if "Remove internal data zero initialization" is set. For example, the following image illustrates the initialization of "maxData" if these blocks are placed inside an "Initialize Function" block:
Thus, you can include all the zero-valued DSM blocks that need to be initialized in the "Initialize Function" block and leave the rest of the zero-valued DSM blocks outside. 

More Answers (0)

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!