How can I call external functions in different paths within App Designer

14 views (last 30 days)
I am constructing a GUI using APP Designer from a .m script, which calls some developed functions. My .mlapp file is in C:\GUI_files.
The problem is simplified as:
Within the main body, the main function A is called in a callback function for a button, A is in the same path with .mlapp (C:\GUI_files). Within function A, another function B is called which is in path C:\GUI_files\toolfunc, it is accessed in A by command 'addpath[C:\GUI_files\toolfunc] '. Within function B, function C is called, which is in a .p file and not readable. Function C is in path 'C:\GUI_files\toolfunc\toolfunc\tolls', which is a subfolder of B's path. Within B, the func C is accessed by command 'add path[C:\GUI_files\toolfunc\tools] '. That means the function will call another function in a different path.
It works well in the MATLAB environment, however, it shows error when I make it to a standalone Desktop APP. I assume that maybe the path changing command does not work within a packed App, because with the Compiler no folder can be chosen but only files. Because of the .p file, I cannot see the complete function, so I am not sure if the problem is it. So I want to ask, if the different paths of the called functions/ 'addpath' and 'cd' commands matter the standalone Desktop application?

Accepted Answer

Arthur Roué
Arthur Roué on 10 Jul 2020
Edited: Arthur Roué on 10 Jul 2020
You should use relative path instead of absolute one, especially if you make your app standalone.
For instance, you can get parent folder path of a running function with :
ParentFolder = fileparts(mfilename)
If you write this line in your main function, the output will be C:\GUI_files. You can also use pwd function.
I also prefer to define my environment path in a startup function instead of adding new folder to path throught programm execution.
It's also possible that the function in a p file call another function which is not package in your standalone because MATLAB can't detect dependencies of P-Files. In this case, you have to manually add the required function to the standalone.
  4 Comments
Tian Zhao
Tian Zhao on 29 Jul 2020
Yes. Thanks a lot for your suggestions! ctfroot can find the path where the functions for App are deployed. However, it does not work since maybe there are codes for path changing within the .p file. I shifted the .p file and all of the relevant functions to a public drive, so that it and the dynamically generated .txt data can be accessed during the execution. In any case, thanks for your kind help :)

Sign in to comment.

More Answers (0)

Categories

Find more on Debugging and Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!