How can I pass arguments to executable simulink?
7 ビュー (過去 30 日間)
古いコメントを表示
I want to enter some block variables from outside in a simulink project that I compiled with embedded coder. What is the most appropriate way to do this? I tried to update it by reading a file in an s-function, but I got a "file could not be opened" error during the compilation phase of the simulink.
1 件のコメント
Shivansh
2024 年 8 月 6 日
Hi talha,
You can read the file in MATLAB and then access the variables in Simulink.
You can refer to the following documentation link for more information about importing files in MATLAB: https://www.mathworks.com/help/matlab/import_export/ways-to-import-text-files.html.
回答 (1 件)
Ayush
2024 年 8 月 6 日
編集済み: Ayush
2024 年 8 月 6 日
Hello Talha,
To pass arguments to control/modify the parameter fields of a block that is already part of a compiled Simulink project, the most optimal way is to utilize external parameters. This would ensure that the parameters controlling the variables are accessible during the simulation and code generation phase. You can achieve the same by:
1. First defining the parameters in the MATLAB workspace or in a script or config file that you run before the simulation and code generation.
2. Then you can create "Simulink.Paramater" objects for each of the parameters to give finer control over specific storage classes as well as other properties necessary for code generation. You can refer to the below documentation to know more about the "Simulink.Parameter" object:
Here is an example code as well for further reference:
param1 = Simulink.Parameter(10);
param1.CoderInfo.StorageClass = 'ExportedGlobal';
param2 = Simulink.Parameter(20);
param2.CoderInfo.StorageClass = 'ExportedGlobal';
3. In the Simulink model, reference these defined parameters in the block parameters field and configure the code generation process to support external parameters. You can refer to the following documentation to understand how to allow external parameters in code generation:
4. Generate the code using Embedded Coder where the parameters are now included in the generated code as global variables and can now be modified externally.
5. You can now modify the parameter values in the generated code or through an external header/config file.
Hope it helps!
0 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!