Filter löschen
Filter löschen

Passing Custom Command Line Arguments to a Compiled Simulink Model

6 Ansichten (letzte 30 Tage)
Leon Sievers
Leon Sievers am 19 Jun. 2024
Beantwortet: R am 20 Jun. 2024
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

Akzeptierte Antwort

R
R am 20 Jun. 2024
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

Weitere Antworten (0)

Produkte


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by