Use of variables in Configuration Parameters -> Custom Code

12 次查看(过去 30 天)
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?
  1 个评论
Braulio Horta
Braulio Horta 2024-10-11
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.

请先登录,再进行评论。

回答(1 个)

Abhinav Aravindan
Abhinav Aravindan 2024-10-9
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:
  1. 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!
  1 个评论
Braulio Horta
Braulio Horta 2024-10-11
编辑:Braulio Horta 2024-10-11
It works but, as I mentioned in the original question, I was thinking about an approach where I don't have to change the parameter.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by