Initialize Values to Inports in Embedded Coder
2 views (last 30 days)
Show older comments
Hello all,
I am trying to initialize my Simulink model's inports with some variables. Currently I have done the same using the Root Inport Mapper and used a .mat file along with it to initialize my inports. The values are being initialized when I run the model although they do not show up in the model_init function in the generated C code of the model.
Can anyone tell me how to initialize values to inports that show up in the generated C code using Embedded Coder?
0 Comments
Answers (1)
Anudeep Kumar
on 1 Apr 2025
Hello Atif,
I've experienced a similar situation, and I found that Code Mappings provided an effective solution. In Simulink, Code Mappings are integral to the code generation process, allowing you to specify how model elements are represented in the generated code. This feature is especially beneficial when using Embedded Coder to produce high-quality C/C++ code. I recommend reviewing the Code Mapping documentation and exploring some examples to better understand the workflow based on your model's requirements.
Code Mapping Documentation:
How to choose Data Configuration Approach: This page will help you answer various questions like what data elements to use, where to store the data, how to configure data to meet code generation objectives.
I hope these documentations help!
4 Comments
Anudeep Kumar
on 11 Apr 2025
Edited: Anudeep Kumar
on 11 Apr 2025
I wanted to clarify our previous discussion regarding the use of root-level inports to map a MAT file to inports. I realize there was a misunderstanding on my part, as I have worked on just Code Mapping, which differs from your specific use case.
In my search for a solution, I discovered an example that demonstrates how to initialize root-level inports in the manner you require. I'm currently exploring how they set default values for these inports. Meanwhile, I've included a link to the relevant documentation. You might find it helpful to open the model and experiment with it yourself.

I have also attached a screenshot of model and the model itself.
See Also
Categories
Find more on Deployment, Integration, and Supported Hardware 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!