필터 지우기
필터 지우기

Passing Custom Command Line Arguments to a Compiled Simulink Model

조회 수: 6 (최근 30일)
Leon Sievers
Leon Sievers 2024년 6월 19일
답변: R 2024년 6월 20일
Hello,
I'd like to pass command line arguments to a compiled GRT Simulink model. The idea is to overwrite pre defined variables used in the model, e.g. in a Constant block. So far I could not find any information on this.
Thank you in advance for your help!
Best,
Leon

채택된 답변

R
R 2024년 6월 20일
Passing command-line arguments to a compiled GRT Simulink model, with the objective of modifying predefined variables like those in a Constant block, presents a challenge as the compiled executable from a GRT target does not inherently possess the capability to parse command-line arguments as a traditional C or C++ program might.
This is primarily because the GRT target is tailored for real-time simulation and code generation, prioritizing the deterministic execution of Simulink models over accommodating general-purpose programming features such as argument parsing.
To adapt the generated code for such tasks, begin by identifying the function where model parameters are initialized. When utilizing code generated from a model, you typically interact with generated entry-point functions, such as step and initialize. For a comprehensive understanding of how generated code can interact with external environments, consider consulting the documentation at: https://www.mathworks.com/help/rtw/ug/how-generated-code-exchanges-data-with-an-environment.html
To make internal data, like a gain value, externally adjustable, it should be declared as a parameter object, such as Simulink.Parameter. Detailed guidance on this process can be found in the documentation section here.
To incorporate command-line argument parsing into your project, you'll need to manually integrate standard C code that can interpret the arguments (argc and argv) and subsequently adjust the model's parameters accordingly. This may require converting argument strings into their respective data types (e.g., using atoi or atof for integers or floats).
For further assistance on calling C or C++ library functions from MATLAB, you might find the following resources helpful:
  1. https://www.mathworks.com/help/matlab/call-c-library-functions.html
  2. https://www.mathworks.com/help/matlab/call-cpp-library-functions.html

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by