
How can I define relative paths in the S-Function Builder using environment variables?
조회 수: 26 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2024년 9월 12일
답변: MathWorks Support Team
2024년 9월 18일
I need to avoid hardcoding absolute paths to easily share the files with others. How can I use environment variables to define the search paths for building S-Functions when using an S-Function Builder block?
채택된 답변
MathWorks Support Team
2024년 9월 12일
If the files that need to be included are in a folder relative to the model build directory, you can use "." and ".." to refer to the current folder and its parent folder, respectively.
If the files are in a directory that is more difficult to refer to, use environment variables to set the path. To include a header file named "myheader.h" in a directory specified by the environment variable "MY_PATH" in R2014a-R2020a, use the following:
ENV_PATH $MY_PATH
INC_PATH $MY_PATH
myheader.h
Beginning with release R2020b, use the new S-Function Builder editor to set the ENV_PATH and INC_PATH in the "Libraries" section, and additionally specify the file using an ENTRY tag.
To use a MATLAB variable as part of a path, use "setenv" to set an environment variable to the same path. This is only persistent for the current MATLAB session. For more information, visit the "setenv" documentation:
As an example, setting a relative path to a source file "mySource.c" could look like this:
Set the Environment Variable in MATLAB to the folder where the source file is located:
>> setenv("MY_PATH","C:\...\myProject")
And then in the S-Function Builder add the following paths and entries in the "Libraries" section via the "Insert Paths" button at the top:

Also, paths that use environment variables can build off of them like any other path. For example:
SRC_PATH $MY_PATH/myfolder
댓글 수: 0
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!