How can I exclude a file from the automatic dependency analysis performed by MATLAB Compiler?

14 views (last 30 days)
I am using the Application Compiler to compile a MATLAB function, which loads a MAT file. I want to be able to change the MAT file after the application has been compiled and then load the new parameters. In R2016a, I was able to not add the MAT file in the "Files required for your application to run" but to add it under "Files installed for your end user". Then the file would be loaded at run-time.
In R2016b or later, the MAT file is automatically detected by the dependency analysis and cannot be removed from the list "Files required for your application to run". If I try to remove the file, it will appear there again after a second.
I am compiling the following function:
function test() % test.mat containing the scalar value "tmp=1" load('test.mat') disp(tmp)
and the corresponding MAT file "test.mat" is located in the same folder.
How can I exclude the file "test.mat" from the automatic dependency analysis?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 5 Nov 2024 at 0:00
Edited: MathWorks Support Team on 22 Oct 2024
Since R2016b, there is a new MATLAB Compiler feature to automatically include dependent files, such as MAT files, text, spreadsheets, images, audio, or video when packaging standalone applications. For more information, see Dependency Analysis Using MATLAB Compiler.
In R2020a and later versions:
You can use the "%#exclude" pragma to ignore a file or function dependency during dependency analysis while executing the 'mcc' command or deployment app.
For details, refer to the following documentation:
In R2019b and earlier versions:
It is not possible to remove a file after it has been detected by the dependency analysis.
However, you can change the command for loading the file to contain a path element, such as:
load('./test.mat')
Then, the MAT file will not detected by the dependency analyzer and you can load it at run-time.
Note that this workaround may not work when absolute paths are being used, for example:
data = load('\\networkdrive\project\application\datasets\data.mat')
In these situations, one can use "eval" to hide the load command from the dependency analyzer.
Generally speaking, a best practice to exclude certain dependencies when compiling MATLAB code, is to structure the code such that different paths or functions are used for the deployed application. This can be done by using the "isdeployed" command. Refer to the documentation below:
See the latest documentation for more details on Writing Deployable MATLAB Code:

More Answers (0)

Categories

Find more on C Shared Library Integration in Help Center and File Exchange

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!