Initialize Values to Inports in Embedded Coder

4 vues (au cours des 30 derniers jours)
Atif Penkar
Atif Penkar le 25 Fév 2025
Modifié(e) : Anudeep Kumar le 11 Avr 2025
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?

Réponses (1)

Anudeep Kumar
Anudeep Kumar le 1 Avr 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 commentaires
Atif Penkar
Atif Penkar le 3 Avr 2025
Hi Anudeep, unfortunately due to IP restrictions at my organization I can not share the model. If you have a sample model which I can refer, that would be really helpful.
Anudeep Kumar
Anudeep Kumar le 11 Avr 2025
Modifié(e) : Anudeep Kumar le 11 Avr 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Deployment, Integration, and Supported Hardware dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by