Recently, I realized I can use environment variables enclosed in % (i.e. windows syntax) in these parameters. It helps but does not solve my problem entirely.
Use of variables in Configuration Parameters -> Custom Code
9 views (last 30 days)
Show older comments
I have a simulink model that uses s-functions and also I compile it using Simulink Coder. The problem is that I have additional build information, especially, Custom Code Include Directories ('CustomInclude') and Custom Code Libraries ('CustomLibrary') that are machine specific and I would like to define these paths indirectly using an environment variable, workspace variable, user function or any other method.
I'm trying to avoid using a script to change there parameters (so the model does not "get dirty" when there is no real change).
The s-function builder block has a similar feature where one can use enviroment variables. I was able to use it successfully in another case.
Can I use any type of variable in the Custom Code Parameters?
Answers (1)
Abhinav Aravindan
on 9 Oct 2024
I understand that you are looking for a way to list directories and libraries in the "Custom Code" section of “Configuration Parameters” using variables as they are system specific. One possible way to do this is by using MATLAB workspace variables and the "PostLoadFcn" model callback. This can be done by the following steps:
- Define the required directory paths and libraries to the MATLAB workspace.
dirCI = "space-separated list of folders"
libsCI = "space-separated list of library files"
2. In Simulink, you can go to Modelling -> Setup -> Model Properties and add the following to “PostLoadFcn” model callback as follows:
set_param('modelName', 'CustomInclude', dirCI);
set_param('modelName', 'CustomLibrary', libCI);
The model will add the directories and libraries set in the MATLAB workspace after the model is opened. However, it is to be noted that if the paths and library variables are changed in the MATLAB workspace, you will need to close the model and reopen it to update the custom code inclusions.
Please find the related documentation below for your reference.
I hope this helps!
See Also
Categories
Find more on Simulink Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!