Modifying the search path is not supported by Matlab Compiler?

Trying to create a Matlab app in R2023b. The deployed application should connect to a Moku:Go device (which is using its own Matlab toolbox) and take some measurements. The app is running smoothly when running from Matlab, but giving an error message when running from the deployed standalone app.
I have added the following line in my Matlab startup code and have made sure that all the required Moku files are embedded during the app deployment:
addpath(genpath('C:\Users\username\AppData\Roaming\MathWorks\MATLAB Add-Ons\Toolboxes\moku-MATLAB(2)'))
Please advise what can be done to have the deployed app running.

 Accepted Answer

Try taking that line of code out of your program. To add files that the compilation process may not see and automatically include you can use the '-a' option of mcc.

More Answers (2)

See the "Do Not Rely on Changing Directory or Path to Control the Execution of MATLAB Files" section on this documentation page. If you need to add a directory to the MATLAB search path in order for the files it contains to be visible to MATLAB Compiler, do so before trying to create the application rather than inside the application itself. Or use the -a option for mcc as Image Analyst suggested. Also see this documentation page.
Thank you both! Adding the line shown below to the deployment settings worked for me. It basically included all the files from the specified folder, which obviously made the installer package much larger (which is fine). To be honest, I don't understand the statement "Try taking that line of code out of your program." How can it be taken out of the program, if that line is what makes the app to connect to the Moku:Go?
-a 'C:\Users\username\AppData\Roaming\MathWorks\MATLAB Add-Ons\Toolboxes\moku-MATLAB(2)'

2 Comments

You said you have this line in your program:
addpath(genpath('C:\Users\username\AppData\Roaming\MathWorks\MATLAB Add-Ons\Toolboxes\moku-MATLAB(2)'))
remove that line.
Put that '-a' line on the mcc line, either on command line, or in a m-file script that you use to compile and possibly do other things (which is what I do), or use deploytool to use the -a option (which is what you're doing).
Alternately, if you need to add this directory to your path when you're running your application in MATLAB (not as a deployed application), wrap it in:
if ~(ismcc || isdeployed)
end
as the documentation to which I linked showed you.

Sign in to comment.

Categories

Products

Release

R2023b

Community Treasure Hunt

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

Start Hunting!