Initialize Values to Inports in Embedded Coder

조회 수: 2 (최근 30일)
Atif Penkar
Atif Penkar 2025년 2월 25일
편집: Anudeep Kumar 2025년 4월 11일
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?

답변 (1개)

Anudeep Kumar
Anudeep Kumar 2025년 4월 1일
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
Atif Penkar
Atif Penkar 2025년 4월 3일
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 2025년 4월 11일
편집: Anudeep Kumar 2025년 4월 11일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Deployment, Integration, and Supported Hardware에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by