How do I lock the current directory while a GUI-based program is running?
조회 수: 6 (최근 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!