Clear Filters
Clear Filters

How can I pass arguments to executable simulink?

7 views (last 30 days)
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 Comment
Shivansh
Shivansh on 6 Aug 2024
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.

Sign in to comment.

Answers (1)

Ayush
Ayush on 6 Aug 2024
Edited: Ayush on 6 Aug 2024
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!

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!