How can I define relative paths in the S-Function Builder using environment variables?

28 visualizaciones (últimos 30 días)

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?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 12 de Sept. de 2024
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

Más respuestas (0)

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by