Why do I get a "Previously accessible file is now inaccessible" error message when running a deployed standalone application created with MATLAB Compiler?

I have a MATLAB code with GUI which runs fine when executed from the MATLAB Command Window. I can build it successfully, but when I try to run the compiled app, I get the following error:
The file 'C:\Users\<username>\Documents\GUI_main.m' is not in the application's expanded CTF archive at 'C\Users\<username>\AppData\Local\Temp\<username>\mcrCache7.17\GUI_ma1'. This is typically caused by calls to ADDPATH in your startup.m file or matlabrc.m files. Please see the compiler documentation and use the ISDEPLOYED function to ensure ADDPATH commands are not executed by deployed applications. Previously accessible file  "C:\Users\<username>\Documents\GUI_main.m" is now inaccessible.
Are some of my "addpath" commands causing this issue? How do I resolve this?

 Accepted Answer

When running a standalone application which was compiled with the MATLAB Compiler, all lines of the compiled script are executed. Consequently, the "addpath" command executes and sets the same folders as on the machine on which it was deployed. However, these specific paths are not recognized on the machine where the standalone application is executed. This is why the error occurs.
To resolve this, use "isdeployed" to ensure that "addpath" commands are not executed when running a deployed applications. For example, the part inside the if-block will not run when the app is run in a deployed state.
if(~isdeployed) addpath(...); end % your code goes here

More Answers (0)

Categories

Products

Release

R2018a

Community Treasure Hunt

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

Start Hunting!