How do I lock the current directory while a GUI-based program is running?
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I've got a large GUI-based program that I'd like to error-proof by ensuring that the user doesn't change the current directory.
E.g., if she changes the directory, and then tries to close the program, an error comes up because MATLAB can no longer find the CloseRequestFcn. :( Same goes for countless other cases.
Any idea how this might be done? (My backup plan is to just make the main GUI window modal, preventing any other MATLAB window from being selected.)
0 comentarios
Respuesta aceptada
Jan
el 23 de Mzo. de 2012
Modal dialogs are not user-friendly, therefore I recommend to avoid this feature whenever it is possible.
Arthur's suggestion to add the folder to the Matlab path is the standard solution for finding functions in a specific folder.
further methods are nested functions and the creation of function handles to all subfunctions during the creation of the GUI. These function handles are independent from the current folder.
Más respuestas (2)
Arthur
el 23 de Mzo. de 2012
Why don't you simply add your path to the MATLAB search pad? Then you'll never have this problem. If you want, you can even add this to the openingFcn of your GUI.
doc addpath
GUI_script = mfilename(); %name of the file
GUI_path = mfilename('fullpath'); %full path including filename
GUI_path = regexprep(GUI_path,GUI_script,'');%full path without file name
%add GUI path to search pad
addpath(GUI_path)
0 comentarios
SAIM HAQUE
el 23 de Mzo. de 2012
hello, ALEX, i'have some suggestion, just right click to any folder, and select "ADD PATH"-->"Select folders and sub folders".
In this way, you place m-file into any other folder and acceess it easily.
0 comentarios
Ver también
Categorías
Más información sobre Search Path 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!