How can I call external functions in different paths within App Designer
13 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Arthur Roué
2020-7-10
编辑:Arthur Roué
2020-7-10
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Debugging and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!