How can I call external functions in different paths within App Designer
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tian Zhao
el 10 de Jul. de 2020
Comentada: Tian Zhao
el 29 de Jul. de 2020
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 comentarios
Respuesta aceptada
Arthur Roué
el 10 de Jul. de 2020
Editada: Arthur Roué
el 10 de Jul. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Debugging and Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!