How do I lock the current directory while a GUI-based program is running?
16 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Jan
2012 年 3 月 23 日
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.
その他の回答 (2 件)
Arthur
2012 年 3 月 23 日
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 件のコメント
SAIM HAQUE
2012 年 3 月 23 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Search Path についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!